Huawei Developers
Published in

Huawei Developers

Intermediate: How to integrate Huawei Cloud Functions in Android

In this article, we will be integrating Huawei Cloud Functions which enable serverless computation. It provided Function as a Service(FaaS) capabilities to simply the application development and O&M by splitting service logic into functions and offers Cloud Functions SDK that works with Cloud DB and Cloud Storage so that app implemented more easily.

Introduction

In this article, we will be integrating Huawei Cloud Functions which enable serverless computation. It provided Function as a Service(FaaS) capabilities to simply the application development and O&M by splitting service logic into functions and offers Cloud Functions SDK that works with Cloud DB and Cloud Storage so that app implemented more easily.

The best part of the Cloud Functions are it can automatically scales based on the actual traffic, you need not bother about the freeing server resource and helping you to reduce cost.

How the Service Works

AppGallery connect (AGC) gives you capability where you can upload you nodejs and run you code. It also provides inline code functionality where you can create and modify files which contains functions like Cloud DB and Cloud Storage. Simple functions which performs your desired task, this function you can change any time and save it and you need not have to change the app side code.

To achieve this AppGallery provides Trigger,which allows you to make HTTP request (POST) to trigger the function in Cloud Function, Cloud DB trigger for data deletion or insertion requests after Cloud DB is integrated. Once you integrate Cloud Functions SDK meets conditions of specific function triggers, your app can call the cloud functions, and you can also test the function in AGC, which greatly facilitates service function building.

Platform Supported

Prerequisites

1. Must have a Huawei Developer Account.

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

Integration Preparations

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. Create project in AppGallery Connect

4. Enabling Cloud Function

5. Configuring a Function

How to add Function?

How to add trigger?

Edit your function in inline code editor

How to trigger Cloud Function via http from Android?

How can test Cloud Function in AGC?

Login to AGC and click My projects.

Choose your project, navigate to Build > Cloud Functions and then select Functions.

To test function, you need to give valid JSON input.

Result

Tips and Tricks

  • Make sure you are already registered as Huawei developer.
  • Enable Huawei Cloud Function in the App Gallery.
  • Make sure you have added the agconnect-services.json file in app folder.
  • Make sure all the dependencies are added properly.

Conclusion

In this article, we have learnt integration of Huawei Cloud Functions in Android applications. In this sample I tried to show how Cloud Functions helps admin to change the Admin login credentials from Cloud Functions without changing the Android application code. In similar passion you can create own function as per your requirement and use of Huawei Cloud Functions capabilities of FaaS.

I hope you have read this article. If you found it is helpful, please provide likes and comments.Thank you so much for reading, I hope this article helps you to understand the Huawei Cloud Functions capabilities of FaaS.

Reference

Huawei Cloud Functions

Checkout in forum

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store