Hms core android studio

Содержание
  1. Hms core android studio
  2. Overview
  3. What You Will Create
  4. What You Will Learn
  5. Hardware Requirements
  6. Software Requirements
  7. Adding Build Dependencies
  8. 1. Open the build.gradle file in the app directory.
  9. 2. Configure build dependencies.
  10. 3. Open the modified build.gradle file. You will find a Sync Now link in the upper right corner of the page. Click Sync Now and wait until synchronization is complete.
  11. 4. Define multi-language settings.
  12. Configuring Obfuscation Scripts
  13. 1. Open the obfuscation configuration file proguard-rules.pro of your Android project.
  14. 2. Add configurations to exclude the HMS Core SDK from obfuscation.
  15. 3. If you are using AndResGuard, add it to the trustlist in the obfuscation script file.
  16. Signing In with a HUAWEI ID
  17. Handling a LOGIN Button Event
  18. Calling the Files.create API to Create a Folder and Upload a File
  19. API Description
  20. Setting the Read and Write Permissions
  21. Handling a CREATE FOLDER AND UPLOAD FILE Button Event
  22. Calling the Files.list API to Query File Details by File Name
  23. API Description
  24. Handling a QUERY FILE Button Event
  25. Calling the Files.Get API to Download a File
  26. API Description
  27. Handling a Download THE FILE Button Event
  28. Calling the Comments.Create API to Comment on a File
  29. API Description
  30. Handling a COMMENT THE FILE Button Event
  31. Calling the Comments.List API to List Comments on a File
  32. API Description
  33. Handling a QUERY COMMENTS Button Event
  34. Calling the Replies.Create API to Reply to a Comment
  35. API Description
  36. Handling a REPLY THE COMMENT Button Event
  37. Calling the Replies.List API to List Replies to a Comment
  38. API Description
  39. Handling a QUERY REPLIES Button Event
  40. Calling the HistoryVersion.List API to List Historical Versions of a File
  41. API Description
  42. Handling a LIST HISTORYVERSION Button Event
  43. Follow-up
  44. Downloading the Drive Sample Code
  45. What Else You Can Do
  46. Hms core android studio

Hms core android studio

Overview

HMS Core Drive SDK allows you to create apps that use the HUAWEI Drive Kit service. HUAWEI Drive Kit provides cloud storage for your apps, enabling users to store files that are created when using your apps, including photos, videos, and documents, in HUAWEI Drive (Drive for short), as well as download and synchronize these files on demand. HUAWEI Drive Kit also provides comprehensive data protection, empowering users to manage their data securely and conveniently.
The current core capabilities include uploading, downloading, searching for, and commenting on files in Drive, replying to comments, querying file changes, and obtaining notifications.

What You Will Create

In this codelab, you will create an Android app that is capable of using HUAWEI Drive Kit. By integrating Drive Kit into your app, the app will allow users to manage and edit files in Drive with optimal convenience, with the ability to store photos, drawings, recordings, videos, and designs in Drive, and access files in Drive from any smartphone, tablet, or computer.

What You Will Learn

  • How to develop Android apps using Android Studio.
  • How to create apps and configure Drive services for the apps on HUAWEI Developers.
  • How to obtain the HMS Core Drive SDK and develop apps based on the Drive SDK.

Hardware Requirements

  • A computer (desktop or laptop)
  • A Huawei phone (with the USB cable), which is used for debugging

Software Requirements

  • Java JDK installation package
  • Android SDK package
  • Android Studio 3.X
  • HMS Core (APK) 3.X or later

To integrate HUAWEI HMS Core, you must complete the following preparations:

  • Create an app in AppGallery Connect.
  • Create an Android Studio project.
  • Generate a signing certificate.
  • Generate a signing certificate fingerprint.
  • Configure the signing certificate fingerprint.
  • Add the app package name and save the configuration file.
  • Add the AppGallery Connect plug-in and the Maven repository in the project-level build.gradle file.
  • Configure the signature file in Android Studio.

Note: You need to register as a developer to complete the operations above.

Adding Build Dependencies

1. Open the build.gradle file in the app directory.

2. Configure build dependencies.

Note: To use HUAWEI Drive Kit, you will need to integrate HUAWEI Account Kit.

3. Open the modified build.gradle file. You will find a Sync Now link in the upper right corner of the page. Click Sync Now and wait until synchronization is complete.

Note: If an error occurs, check your network connection and the configurations in the build.gradle file.

Читайте также:  Микрофон для андроид телевизора

4. Define multi-language settings.

● Skip this step if your app does not require support for additional languages. By default, your app supports all languages provided by the HMS Core SDK.

● If your app uses only some of these languages, follow the operation procedure in this section to complete the required configuration.

Open the build.gradle file in the app directory of your project.

Go to android > defaultConfig and add the resConfigs configuration. For example, if your app supports only English and Simplified Chinese, the configuration is as follows:

Configuring Obfuscation Scripts

Before building the APK, configure obfuscation scripts to prevent the HMS Core SDK from being obfuscated. If obfuscation arises, the HMS Core SDK may not function properly.

1. Open the obfuscation configuration file proguard-rules.pro of your Android project.

2. Add configurations to exclude the HMS Core SDK from obfuscation.

3. If you are using AndResGuard, add it to the trustlist in the obfuscation script file.

The sample code provided in this section contains undefined global variables and methods. You can download the sample code to view their definitions.

Signing In with a HUAWEI ID

Handling a LOGIN Button Event

To implement the sign-in function through the HMS Core SDK, you will need to set the Drive scope for obtaining the permission to access Drive APIs.

Each Drive scope corresponds to a certain type of permissions. You may apply for the permissions as needed. For details about the corresponding APIs, please refer to HUAWEI Account Kit Development Guide. If the app user has not signed in with a HUAWEI ID, the HMS Core SDK will prompt the user to sign in.

Possible causes for a sign-in failure:
1. The HUAWEI Mobile Services (APK) version is incorrect. The required version is 3.0 or later.
2. Required services are not enabled. Enable the services on HUAWEI Developers.
3. The agconnect-services.json file is in the wrong directory. Copy the file to the app’s root directory.

Note:
1. For details about the currently supported locations, please refer to Supported Locations.
2. To initialize Drive, your app needs to prompt the user to go to the account center and ensure that Drive Kit has been enabled.

Calling the Files.create API to Create a Folder and Upload a File

API Description

API description:
This API is used to create a file and a folder. For details about the API, please refer to HUAWEI Drive Kit Development Guide.

Setting the Read and Write Permissions

Add the read and write permissions on the phone storage to app/src/main/AndroidManifest.xml.

Add a permission request to MainActivity.java.

Add the code snippet for requesting the permissions to the onCreate method.

Handling a CREATE FOLDER AND UPLOAD FILE Button Event

Create a folder in the root directory of Drive, and upload the file in the designated directory to the folder. Note that the code contains global variables and functions, and you can download the sample code to view their meanings.

After the folder is created and the file is uploaded, the user can view the file by going to Files > HUAWEI Drive.

If applicationData is selected, the operation will be performed on the app data folder. The app data folder is invisible to users and is used to store app-specific data.

FAQs:
Q: What should I do if the folder already exists and cannot be created?
A: Sign in to Drive and delete the existing folder.
Q: Why cannot the file be read?
A: Verify that the path is correct, and that the permissions have been set successfully.
Q: Why did a file upload fail?
A: Go to Account center > Cloud and check whether available storage space is sufficient.

Calling the Files.list API to Query File Details by File Name

API Description

Handling a QUERY FILE Button Event

In the query input box, enter a file name to query file details. If applicationData is selected, the operation will be performed on the app data folder.

Читайте также:  Свои виджеты для android

In this demo, the file details include the file name (fileName), file ID (id), and file size (size). If two files share the same name, only the details of one such file are shown in this demo. For more information about file details, please refer to HUAWEI Drive Kit References.

Calling the Files.Get API to Download a File

API Description

Handling a Download THE FILE Button Event

Tap the DOWNLOAD THE FILE button to download the file queried using the QUERY FILE function.

After the file is successfully downloaded, you can view it in the /Huawei/Drive/DownLoad/ directory.

Calling the Comments.Create API to Comment on a File

API Description

Handling a COMMENT THE FILE Button Event

In the comment input box, enter a comment on the file queried using the QUERY FILE function.

After the comment is successfully added, you can view all comments on the file by using the QUERY COMMENTS function.

Calling the Comments.List API to List Comments on a File

API Description

Handling a QUERY COMMENTS Button Event

List all comments on the file queried using the QUERY FILE function.

The following figure shows an example of the listed comments. In this demo, the comment details include the comment content (description), comment ID (id), and reply content (replies/description).

Calling the Replies.Create API to Reply to a Comment

API Description

Handling a REPLY THE COMMENT Button Event

In the reply input box, enter a reply to the comment created using the COMMENT THE FILE function.

After the reply is successfully added, you can view all replies to the comment using the QUERY REPLIES function.

Calling the Replies.List API to List Replies to a Comment

API Description

Handling a QUERY REPLIES Button Event

List all replies to the comment created using the COMMENT THE FILE function.

The following figure shows an example of listed replies. In this demo, the reply details include the reply content (description) and reply ID (id).

Calling the HistoryVersion.List API to List Historical Versions of a File

API Description

Handling a LIST HISTORYVERSION Button Event

List all historical versions of the file queried using the QUERY FILE function.

The following figure shows an example of listed historical versions. In this demo, the historical version details include the version ID (id) and version SHA256 (sha256).

Follow-up

In your Android Studio, click Run. Select your mobile phone as the target, and click OK to run the Drive demo on the mobile phone. The following page will display.

Downloading the Drive Sample Code

You can click the following button to download the Drive Kit sample code used in this codelab:

Well done. You have successfully developed your first app using Drive Kit!

In this codelab, you have learned:

  • How to integrate the Drive SDK and create an app using Drive Kit.
  • How to run the Drive Demo project in Android Studio.

You have now learned all of the key operations required to create an app that uses Drive Kit.

What Else You Can Do

You can read code snippets in the following file:
com/huawei/www/driveapplication/MainActivity.java

For more information, please click the following link:

Источник

Hms core android studio

In this section, you will create a project and an app in AppGallery Connect.

  1. Sign in to AppGallery Connect and click My projects.
  2. On the page displayed, click Add project.
  3. On the New project page, enter a project name and click OK.
  4. On the General information tab page, click Add app.
  5. On the Add app page, set Platform and Device, enter an app name and package name, select an app category (App or Game) and default language as needed, and click OK.
  6. View app information such as the allocated app ID and client secret in the App information area on the General information tab page after app creation.

In this section, you will create an Android Studio project for your app. During the creation, you will need to use the app name and package name that you have specified in AppGallery Connect.

Читайте также:  Переброска файлов с андроид

  1. Start Android Studio and go to File >New >New Project.
  2. On the Choose your project page, click Empty Activity and then Next.
  3. On the Configure your project page, enter your app name and package name (configured in AppGallery Connect) in the Name and Package name text boxes, set Save location and Minimum API level, and click Finish. You have now created a project for your app.

In this section, you will create a signing certificate file and use it to sign your APK in Android Studio. This signing certificate file will be used to generate an SHA-256 fingerprint later.

  1. Go to Build >Generate Signed Bundle/APK in Android Studio.
  2. On the Generate Signed Bundle or APK page, select APK and click Next.
  3. If you already have a signing certificate file, click Choose existing, select the signing certificate file, and enter the key store password, key alias, and key password of the file. Then, click Next.

If you do not have a signing certificate file, click Create new.

On the page displayed, set related parameters including Key store path, Password, and Alias.

After the signing certificate file is created successfully, the Generate Signed Bundle or APK page will be displayed, showing the signing certificate file information. Click Next on this page.

  • On the page displayed, select V1 and V2 next to Signature Versions, and click Finish. A signed APK will be generated. (This APK can be uploaded to AppGallery Connect to automatically obtain the app package name.)
  • In this section, you will generate an SHA-256 fingerprint using the signing certificate file and keytool provided by the JDK.

      Windows
      a) Open the command-line interface (CLI) using the cmd command, and run the cd command to go to the directory where keytool.exe is located. In the following example, the JDK is installed in the Program Files folder in drive C.

    cd C:\Program Files\Java\jdk\bin

    b) Run keytool -list -v -keystore and respond as prompted. In the command, indicates the absolute path to the app’s signing certificate.
    Example:

    keytool -list -v -keystore C:\TestApp.jks

    c) Obtain the SHA-256 certificate fingerprint.

    macOS
    a) Open Terminal.

    b) Run keytool -list -v -keystore and respond as prompted. In the command, indicates the absolute path to the app’s signing certificate.
    Example:

    keytool -list -v -keystore /Users/admin/Downloads/HmsDemo.jks

    c) Obtain the SHA-256 certificate fingerprint.

    In this section, you will configure the generated SHA-256 certificate fingerprint in AppGallery Connect.

    1. Sign in to AppGallery Connect and click My projects.
    2. Find your app project, and click the desired app name.
    3. Go to Project settings >General information. In the App information area, click Add under SHA-256 certificate fingerprint, and enter the obtained SHA-256 certificate fingerprint.
    4. Click Save.
    1. On the Project settings page, click the Manage APIs tab.
    2. On the Manage APIs tab page, toggle on switches of the services to be enabled.


    Enable required services for your app as needed.

      In the project-level build.gradle file, add related configurations, including the AppGallery Connect plugin and Huawei Maven repository.

    In Gradle 7.0 or later, configuration under allprojects > repositories is migrated to the project-level settings.gradle file.
    The following is a configuration example of the settings.gradle file:

  • Open the app-level build.gradle file (usually app/build.gradle).
  • Add the AppGallery Connect plugin configuration in either of the following methods:
    • Method 1: Add the following configuration under the declaration in the file header:
    • Method 2: Add the plugin configuration in the plugins block.
  • Sign in to AppGallery Connect, go to Project settings >General information. In the App information area, download the agconnect-services.json file.
  • Copy the agconnect-services.json file to your app’s root directory.
    1. Copy the generated signing certificate file HmsDemo.jks to your app’s root directory and open the app-level build.gradle file (usually app/build.gradle).
    2. Add signing information to the android block in the build.gradle file.

      Click Sync Now to synchronize the project.

      If «completed successfully» is displayed, the project is synchronized successfully. Integration preparations are now completed.

      Источник

    Оцените статью