Manage User files by Huawei Cloud Storage with AppGallery Connect in Android (Kotlin)

Murali Akula
Huawei Developers
Published in
5 min readDec 2, 2021

Introduction

In this article, we can learn how to store data in Huawei Cloud Storage with AppGallery Connect. Cloud Storage provides users to store high volumes of data such as images, audio, and videos generated by your users securely and economically with direct device access.

What is Cloud Storage?

Cloud Storage is the process of storing digital data in an online space that extends multiple servers and locations and is maintained by a hosting company. It delivers on-demand with just-in-time capacity and costs and avoids purchasing and managing users' own data storage infrastructure.

This service is majorly used in daily life to store the data is safe and secure. For example, if you have saved any data such as ID Cards, Certificates, or any Personal documents in your local computer or device if it cashes the entire data will vanish. So, if you saved the data in Cloud Storage, then you can upload, view, download, and delete at any time. You don’t need to worry about safety and security. All the safety measurements will be taken by Huawei for Cloud Storage.

Requirements

1. Any operating system (MacOS, Linux and Windows).

2. Must have a Huawei phone with HMS 4.0.0.300 or later.

3. Must have a laptop or desktop with Android Studio, JDK 1.8, SDK platform 26, and Gradle 4.6 and above installed.

4. Minimum API Level 19 is required.

5. Required EMUI 9.0.0 and later version devices.

How to integrate HMS Dependencies

1. First register as Huawei developer and complete identity verification in Huawei developers website, refer to register a Huawei ID.

2. Create a project in android studio, refer Creating an Android Studio Project.

3. Generate a SHA-256 certificate fingerprint.

4. To generate SHA-256 certificate fingerprint. On the right-upper corner of the android project click Gradle, choose Project Name > Tasks > android, and then click signingReport, as follows.

Note: Project Name depends on the user-created name.

5. Create an App in AppGallery Connect.

6. Download the agconnect-services.json file from App information, copy and paste in android Project under app directory, as follows.

7. Enter SHA-256 certificate fingerprint and click Save button, as follows.

Note: Above steps from Step 1 to 7 is common for all Huawei Kits.

8. Click Manage APIs tab and enable Cloud Storage.

9. Add the below maven URL in build.gradle(Project) file under the repositories of buildscript, dependencies and allprojects, refer Add Configuration.

10. Add the below plugin and dependencies in build.gradle(Module) file.

11. Now Sync the gradle.

12. Add the required permission to the AndroidManifest.xml file.

Getting started with Cloud Storage

1. Log in to AppGallery Connect and select My Projects.

2. Select your application.

3. On the displayed page, choose Build > Cloud Storage and click Enable now.

4. On the page displayed, enter Storage instance and click Next.

5. The Define security rules page will be displayed and click Finish.

6. The Cloud Storage is successfully enabled for the project.

7. Choose Build > Auth Service and click Enable now in the upper right corner. Enable Huawei ID in Authentication mode.

8. Open agconnect-services.json file and add storage-related content to the service tag.

Note:

9. Choose Build > Cloud Storage page, can upload, view, download and delete the files in AppGallery Connect, as follows.

Let us move to development

I have created a project on Android studio with empty activity let us start coding.

In the MainActivity.kt we can find the business logic.

In the activity_main.xml we can create the UI screen.

Demo

Tips and Tricks

1. Make sure you are already registered as Huawei developer.

2. Set min SDK version to 19 or later, otherwise you will get AndriodManifest merge issue.

3. Make sure you have added the agconnect-services.json file to app folder.

4. Make sure you have added SHA-256 fingerprint without fail.

5. Make sure all the dependencies are added properly.

Conclusion

In this article, we have learned how to save data in Huawei Cloud Storage with AppGallery Connect. It provides stable, secure, efficient, and easy-to-use, and can free you from development, deployment, O&M, and capacity expansion of storage servers. It enables users to safely and economically store large quantities of data such as photos, audio, and videos generated by users.

I hope you have read this article. If you found it is helpful, please provide likes and comments.

References

--

--