HMS Drive kit

Eray Mekik
Huawei Developers
Published in
11 min readOct 14, 2020

Storing data on the cloud quicker and easier. Let users upload, download, synchronize, and view images, videos, and documents whenever and wherever they want.

Service Introduction

Drive Kit (short for HUAWEI Drive Kit) allows you to create apps that use HUAWEI Drive capabilities. Drive Kit provides cloud storage for your apps, enabling users to store files that are created while using your apps, including photos, videos, and documents, in Drive (short for HUAWEI Drive) as well as download files, upload files, query historical file versions, search for files, comment on the files, and reply to comments. Drive Kit also provides comprehensive data protection, empowering users to manage their data securely and conveniently.

The current core capabilities of Drive Kit include uploading, downloading, and searching for files in Drive, commenting on files, replying to comments, querying historical file versions, querying file changes, and obtaining notifications.

Use Case

HUAWEI Drive Kit provides various Drive capabilities for quickly developing apps that require cloud storage. The current core capabilities include uploading, downloading, and searching for files in Drive, commenting on files, replying to comments, querying historical file versions, querying file changes, and obtaining notifications.

By integrating the Drive SDK (short for HMS Core Drive SDK), you will be able to develop personalized apps allowing users to:

· Manage, edit, and search for files in Drive conveniently.

· Store photos, drawings, recordings, videos, and designs in Drive.

· Access files in Drive from any smartphone, tablet, or computer.

· Receive push notifications when a file in Drive changes.

· Comment on files and reply to comments.

· Query the historical versions of files.

1. Integration Preparations

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.

2. Starting Configuration
Enabling Related Services
Go to My projects > Project Setting > Manage APIs.

Toggle the Account Kit and Drive Kit switches.

Adding the Configuration File

Adding the agconnect-services.json File of the App

1- In HUAWEI Developers AppGallery Connect, click the app that you have created and go to My projects > Project Setting General informationon. In thProjectct area, clicSet**et.

2- Set the app data storage location, and click OK.

3- In the App information area, click agconnect-services.json to download the configuration file.

4- Copy the agconnect-services.json file to the app’s root directory.

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.

Developing a Drive Demo

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 name:

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.

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

API Description

public List list() throws java.io.IOException

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.

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

public Get get(String fileId) throws java.io.IOException

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

public Create create(String fileId, Comment content) throws java.io.IOException

Handling a COMMENT THE FILE Button Event

In the comment input box, enter a comment 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

public Create create(String fileId, String commentId, Reply content) throws java.io.IOException

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

public List list(String fileId, String commentId) throws java.io.IOException

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

public List list(String fileId) throws java.io.IOException

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).

Running the Drive Demo Project

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.

FAQ

1. What types of files can be uploaded to HUAWEI Drive Kit?

All types of files can be uploaded to HUAWEI Drive Kit.

2. How can an app use HUAWEI CLOUD drive?

App users can modify, save, and directly open files in HUAWEI CLOUD drive and can also use HUAWEI CLOUD drive as the expansion of the app storage.

(1) Users can use read software to open files in HUAWEI CLOUD drive.

(2) Users can use photo and file editing software to save files that have been edited on the local PC to HUAWEI CLOUD drive.

3. What is the typical application scenario where the SD watch is used?

Files stored by app users, for example, files created and photos edited by a user on multiple devices at the same time, in HUAWEI CLOUD drive are synchronized to multiple devices in real time. It is recommended that the files be sent in push mode because API-based sending is more traffic consuming.

4. Do HUAWEI Drive Kit functions strongly depend on HUAWEI IDs? Do I need to use a HUAWEI ID to sign in to use HUAWEI Drive Kit functions?

Yes. You must use a HUAWEI ID to sign in to use HUAWEI Drive Kit functions.

5. Does a HUAWEI Drive Kit API allow developers to obtain user authorization? If so, are developers authorized in restricted mode? What is the minimum granularity for reading user authorization?

Yes. Developers can send a scope request to obtain user authorization. Developers can use capabilities claimed in Drive Scope only after being authorized by users.

/auth/drive.file: file access

/auth/drive: all permissions except that on the app directory

/auth/drive.readonly: read-only permission on file content and metadata

/auth/drive.metadata: access to metadata (excluding entities)

/auth/drive.metadata.readonly: read-only permission on metadata (excluding entities)

6. In which European countries is HUAWEI CLOUD drive implemented?

European countries where HUAWEI CLOUD drive is implemented include the following in Northeast Europe and West Europe: Albania, Austria, Bosnia, Bulgaria, Czech Republic, Denmark, Estonia, Finland, Faroe Islands, Greenland, Greece, Croatia, Hungary, Iceland, Liechtenstein, Lithuania, Latvia, Moldova, Montenegro, North Macedonia, Norway, Poland, Romania, Serbia, Sweden, Slovenia, Slovakia, Andorra, Belgium, Switzerland, Cyprus, Germany, Spain, France, UK, Gibraltar, Ireland, Italy, Luxembourg, Monaco, Malta, Netherlands, Portugal, San Marino, and Vatican.

7. Google Drive supports editing, sharing-to-all, and co-editing. Does HUAWEI CLOUD drive support these functions?

According to the plan, the online editing and collaboration and sharing functions will be provided by December 2019.

8. Which editing tool can be used after the editing function is supported? Is WPS available? When will Huawei provide editing software?

According to the plan, Huawei online editing software will be provided in December 2019.

9. Are files stored in HUAWEI CLOUD drive encrypted?

Yes. The files stored in HUAWEI CLOUD drive are encrypted.

10. What are the differences between Firebase Storage and HUAWEI CLOUD drive?

Firebase Storage is an object storage service for developers. Developers can use it to store content generated by users and pay for the storage space.

HUAWEI CLOUD drive is a cloud disk capability provided for users. It allows users to store videos and images and users pay for the storage space. HUAWEI Drive Kit allows developers to manage user files in HUAWEI CLOUD drive.

11. What is the size of the storage space that can be used by a user?

5 GB space is provided for a user free of charge by default. A user can purchase at most 2048 GB space.

12. Are files sorted by file type (image or video) by default?

Files are sorted by modification time by default. The orderBy attribute can be set to sort files on devices. Supported sorting modes include file name and file type.

13. Can files be migrated from other clouds (for example, AWS)?

Currently, files cannot be migrated from other clouds.

14. What are the advantages of HUAWEI Drive compared with other Drives?

HUAWEI Drive allows for encrypted file storage, ensuring higher data security.

16. How many devices does HUAWEI Drive support for data synchronization between devices?

An account can be used to sign in to a maximum of 10 devices. Likewise, HUAWEI Drive supports data synchronization between 10 devices at maximum.

17. What should I do if the folder already exists and cannot be created?

Sign in to Drive and delete the existing folder.

18. Why cannot the file be read?

Verify that the path is correct, and that the permissions have been set successfully.

19. Why did a file upload fail?

Go to Account center > Cloud and check whether available storage space is sufficient.

References

--

--