Integrating Cloud Functions in a Flutter application - Huawei Developers

Cloud Functions enables serverless computing through Function as a Service (FaaS) capabilities to simplify app development and O&M. This helps you implement functions more simply and build service capabilities more quickly. The following describes how to integrate Huawei’s AppGallery Connect Cloud Function service in Flutter.
We will create a basic new project as an example but of course, you could make use of a project you already have that's using flutter!
Project Setup​Install the Flutter environment.​Download the Flutter SDK package and decompress the package to any directory.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Download the Flutter and Dart plugins in Android Studio.
Enable Huawei Cloud Functions​Create an Android app in AppGallery Connect and enable Cloud Functions for it as detailed in this guide.
Now we can go ahead and create a cloud function as you require it to use this guide to help understand what can be done.
Once you are happy with your function (in this instance it might just be as simple as returning a hello world statement for testing) you can go ahead and create a HTTP trigger that will trigger the function.
Create Flutter Project​Next create your flutter project in android studio (or open your existing project if you already have one!).
Download your agconnect-services.json file from the AppGallery Connect console and add it to your project under the ‘app’ directory
Within the project-level build.gradle file make sure to include the Huawei maven repo and add the agcp package as a dependency.
Code:
buildscript {
repositories {
google()
mavenCentral()
maven { url 'https://developer.huawei.com/repo/' }
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath 'com.huawei.agconnect:agcp:1.6.2.300'
}
}
Next in your app level build.gradle apply the agconnect plugin as so:
Code:
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.huawei.agconnect'
Then in your pubspec.yaml file add the Cloud Function SDK dependency.
Code:
dependencies:
flutter:
sdk: flutter
agconnect_cloudfunctions: 1.2.0+300
Call the Cloud function​The below code is an example of how you can call a simple cloud function and get the result returned.
Code:
FunctionCallable functionCallable = FunctionCallable("test-\$latest");
Map<String, dynamic> parameters = <String, dynamic>{
'year': _functionTextController.text
};
FunctionResult functionResult = await functionCallable.call(parameters);
Where test-\$latest is the HTTP trigger identifier.
https://devwithzachary.medium.com/?...-------------------post_sidebar--------------

Good Article

Thanks for sharing!!!

Do we need any special permission for cloud function.

Thanks for sharing!

Related

How to download and Integrate the HUAWEI Account Kit SDK [Android Studio IDE]

1. Android SDK Download
If you are using the Android Studio IDE, download the HMS SDK package and integrate it using the Maven repository. For the integration process, follow the guide below.
Integrating the HMS SDK
You can integrate the HMS SDK no matter whether you are using the Android Studio IDE or Eclipse IDE.
Integrating the HMS SDK into Your App Project in the Android Studio IDE
If you are using Android Studio, you can integrate your HMS SDK by using the Maven repository. Before you start developing an app, integrate the HMS SDK into your Android Studio first.
1. Add the AppGallery Connect configuration file of the app to your AndroidStudio.
a. Sign in to AppGallery Connect and select My apps.
b. Find your app from the list, and click the link under Android App in the Mobile phone column.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
c. Go to Development > Overview > App Information.
d. Click agconnect-service.json to download the configuration file.
e. Copy the agconnect-service.json file to the app root directory.
2. Configure the Maven repository address for the HMS SDK.
a. Open the build.gradle file in the root directory of your AndroidStudio project.
b. Go to allprojects > repositories and configure the Maven repository address for the HMS SDK.
Code:
allprojects {
repositories {
google()
jcenter()
maven {url 'https://developer.huawei.com/repo/'}
}
}
c. Go to buildscript->dependencies and add dependency configurations.
Code:
buildscript {
repositories {
maven { url 'https://developer.huawei.com/repo/' }
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.huawei.agconnect:agcp:1.2.1.301'
}
}
3. Add the AppGallery Connect plug-in dependencies to the end of the file.
a. Open the build.gradle file in the app directory.
b. Configure compile dependencies. (hwid indicates HUAWEI Account Kit.)
Code:
dependencies {
implementation 'com.huawei.hms:hwid:{version}'
}
c. Add the AppGallery Connect plug-in dependency to the file header.
Code:
apply plugin: 'com.huawei.agconnect'
4. Save the modifications. Then click the Synchronize icon in the upper right corner. Wait until synchronization is complete.
5.Multi-language settings.
By default, your app will support all languages supported by the HMS SDK. If your app requires only several languages, configure them as follows; otherwise, skip this task.
Open the build.gradle file in the app directory of your project.
Go to “android”->”defaultConfig” and add the resConfigs configuration. en (English) and zh-rCN (Simplified Chinese) are mandatory. For example, if your app supports only English and Simplified Chinese, the configuration is as follows:
Code:
android{
defaultConfig{
...
resConfigs "en","zh-rCN","Other languages to be supported."
}
}
For details about the languages supported by the HMS SDK, please refer to Languages Supported by HMS SDK.

Earthquake application with Huawei Map and Location kits

Learn how to create a earthquake app that includes the Huawei Map Kit and Location Kit using the Flutter SDK.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Introduction
Hello everyone, In this article, I will make an earthquake application with Flutter. We will make an some APIs provided by the Huawei Map and Location Kit and learn how to use them in an earthquake project.
Huawei Map Kit, provides standard maps as well as UI elements such as markers, shapes, and layers for you to customize maps that better meet service scenarios.
Huawei Location Kit combines the GPS, Wi-Fi, and base station locations to help you quickly obtain precise user locations, build up global positioning capabilities, and reach a wide range of users around the globe.
Configuring The Project
Before you get started, you must register as a HUAWEI developer and complete identity verification on the HUAWEI Developer website. For details, please refer to Register a HUAWEI ID.
Create an app in your project is required in App Gallery Connect in order to communicate with Huawei services.
★ Integrating Your Apps With Huawei HMS Core
Permissions
In order to make your kits work perfectly, you need to add the permissions below in AndroidManifest.xml file.
Code:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
HMS Integration
Check whether the agconnect-services.json file and signature file are successfully added to the android/app directory of the Flutter project.
Add the Maven repository address and AppGallery Connect service dependencies into the android/build.gradle file.
Code:
buildscript {
repositories {
google()
jcenter()
maven { url 'https://developer.huawei.com/repo/' }
}
dependencies {
/*
* <Other dependencies>
*/
classpath 'com.huawei.agconnect:agcp:1.4.1.300'
}
}
Configure the Maven repository address for the HMS Core SDK in allprojects.
Code:
allprojects {
repositories {
google()
jcenter()
maven { url 'https://developer.huawei.com/repo/' }
}
}
Add the apply plugin: ‘com.huawei.agconnect’ line after the apply from: “$flutterRoot/packages/flutter_tools/gradle/flutter.gradle” line.
Code:
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.huawei.agconnect'
Open your app level build.gradle (android/app/build.gradle) file and set minSdkVersion to 19 or higher in defaultConfig. (applicationId must match the package_name entry in the agconnect-services.json file)
Code:
defaultConfig {
applicationId "<package_name>"
minSdkVersion 19
/*
* <Other configurations>
*/
}
Creating Flutter Application
Find your Flutter project’s pubspec.yaml file directory open it and add Huawei Map and Huawei Location Plugins as a dependency. Run the flutter pub get command to integrate the Map & Location Plugins into your project.
There are all plugins in pub.dev with the latest versions. If you have downloaded the package from pub.dev, specify the package in your pubspec.yaml file. Then, run flutter pub get command.
Map Kit Plugin for Flutter
Location Kit Plugin for Flutter
Code:
dependencies:
flutter:
sdk: flutter
http: ^0.12.2
huawei_map: ^4.0.4+300
huawei_location: ^5.0.0+301
We’re done with the integration part! Now, we are ready to make our earthquake application ✓
Make an Earthquake App with Flutter
Create Earthquake Response Data
First of all, we will create an EartquakeResponseData class to access the latest earthquake data. Later, we will call this class with the getData() function.
Additionally, we will use the http package to access the data, so we need to import import ‘package: http / http.dart’ as http; into the detail page.dart class.
More details, you can check https://forums.developer.huawei.com/forumPortal/en/topic/0204423826967890020
Could be useful for some countries.
Very very useful.
Very interesting.
Where are you getting the data for earthQuake and in what format ?

HMS Site kit Integration into Ionic Application | Installation and Example

Introduction
Huawei Site Kit is a development kit for Android applications that provides location search functions like auto-completing keywords, searching for places and providing the details of places. With integrating of this kit into your application, you can search for a destination with keywords including location types like restaurants, hotels, hospitals and 500+ more, and provide detailed information including rating, address and phone number of the place.
You can benefit from Huawei Site Kit’s database by sending queries to its Web API. More than 130 million locations and its detailed information are accessible with easy to use API. All of these services and more is also supported in 13 languages, and 200+ countries.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Usecase
We will use Huawei site kit to search for nearby places based on query entered on search bar. Once we have nearby places, we will show them on Map.
To learn how to show places on Map, refer this article.
Prerequisites
1. Before installing Site Kit, you should have installed npm, Node.js, ionic CLI. To install ionic in system use below command.
Code:
npm install -g @ionic/cli
2. Generate a Signing Certificate Fingerprint. For generating the SHA key, refer this article.
3. Create an app in the Huawei AppGallery connect and enable Site Kit in Manage API section. Provide the SHA Key in App Information Section.
4. Provide storage location.
5. Download the agconnect-services.json.
Installation
1. Open windows CMD or terminal, and create ionic project.
Code:
ionic start Application_Name blank --type=angular
2. Download Cordova Site kit plugin. Navigate to your project root directory and install plugin using npm.
Code:
npm install <CORDOVA_SITE_KIT_PLUGIN_PATH>
3. Install @iONiC-native/core in your project for full ionic support with completion code.
Code:
npm install @ionic-native/core --save-dev
4. Copy the “node_modules\@hmscore\cordova-plugin-hms-map\ionic\dist\hms-map” folder to “node_modules/@iONiC-native” folder under your Ionic project.
5. Compile the project.
Code:
ionic build
npx cap init [appName] [appId]
where appId is package name.
6. After this command, you should add platform to the project. To add, follow command.
Code:
ionic capacitor add android
7. Add agconnect-services.json and signing certificate jks file to the app directory in your Android project as show below.
8. Add maven repository address and agconnect service dependencies in root level build.gradle.
Code:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
maven { url 'http://developer.huawei.com/repo/' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
classpath 'com.google.gms:google-services:4.3.3'
classpath 'com.huawei.agconnect:agcp:1.4.0.300'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
apply from: "variables.gradle"
allprojects {
repositories {
google()
jcenter()
maven { url 'http://developer.huawei.com/repo/' } //This line is added by cordova-plugin-hms-account plugin
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
9. Add signing certificate configuration information in app-level build.gradle.
Code:
signingConfigs {
release {
storeFile file("mykeystore.jks") // Signing certificate.
storePassword "******" // KeyStore password.
keyAlias "******" // Alias.
keyPassword "******" // Key password.
v1SigningEnabled true
v2SigningEnabled true
}
}
10. Add plugin to the app-level build.gradle.
Code:
apply plugin: 'com.huawei.agconnect'
11. Add Site kit dependency in app-level build.gradle.
Code:
dependencies {
implementation 'com.huawei.hms:site:5.0.1.300'
}
12. Sync the project
Code:
npx capacitor sync
13. Import HmsSite in app_module.ts and add it in provider.
Code:
import {HmsSite} from '@ionic-native/hms-site/ngx';
providers: [
StatusBar,
HmsSite,
SplashScreen,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
]
More details, you can check https://forums.developer.huawei.com/forumPortal/en/topic/0204430607447740048

Cordova HMS Map Plugin | Installation and Example

Introduction
In this article, I will explain what Cordova HMS Map Kit is, how to integrate it to the cordova base project and usage of it.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Huawei Map Kit enables communication between HUAWEI Map Kit SDK and Cordova platform. It exposes all functionality provided by HUAWEI Map Kit SDK.
Prerequisites
Before installing Map Kit, you should have installed npm, Node.js and Cordova CLI.
Installation
Let’s start with creating a cordova project. Open Window CMD and create a cordova project like below.
Code:
<p style="line-height: 1.5em;"># create a cordova based project. You can change name of the project as whatever you want.
$ cordova create HMSMapDemo com.hms.mapdemo HmsMap</p>
This command will create a directory called HMSMapDemo where our cordova project is.
After this command, you should add platform to the project. To add, follow command below:
Code:
<p style="line-height: 1.5em;"># first go into cordova project directory
$ cd HMSMapDemo
# add android platform
$ cordova platform add android</p>
Next, add the cordova-plugin-hms-map plugin to your project.
Run the following command in the root directory of your Cordova project to install it through npm.
Code:
<p style="line-height: 1.5em;">$ cordova plugin add @hmscore/cordova-plugin-hms-map</p>
To you use HMSMap plugin, you should have agconnect-services.json and .jks files. Following this guide, you can configure all requirements to use HMS Map Plugin.
After configuration step, finally build project with command below:
Code:
<p style="line-height: 1.5em;">$ cordova build android
</p>
After that, open your android studio project and you are ready to use plugin.
Using Cordova HMS Map Plugin
This section describes how to use the plugin to quickly obtain a map object, change the map type, display my-location on the map, and enable the map’s lite mode.
Creating Map Object
Every map object is bound to a div element in html file. Let’s create a div element in html and change value of id property as “map”.
How can we draw dotted polyline?
that's a nice start...
Mais ficar incrível esse mapa quando tiver completo.

Intermediate: How to Integrate APM Service in Unity Game Development

Introduction
Huawei AppGallery Connect provides Application Performance Management (APM) service provides app performance monitoring capabilities. You can view the analyse app performance data collected by APM in AG Console, this helps to understand the app performance quickly and accurately in real time to rectify app performance problems and continuously improve user experience.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Development Overview
You need to install Unity software and I assume that you have prior knowledge about the unity and C#.
Hardware Requirements
A computer (desktop or laptop) running Windows 10.
A Huawei phone (with the USB cable), which is used for debugging.
Software Requirements
Java JDK 1.7 or later.
Unity software installed.
Visual Studio/Code installed.
HMS Core (APK) 4.X or later.
Integration Preparations
1. Create a project in AppGallery Connect.
2. Create Unity project.
3. Huawei HMS AGC Services to project.
4. Download and save the configuration file.
Add the agconnect-services.json file following directory Assests > Plugins > Android
5. Add the following plugin and dependencies in LaucherTemplate.
Code:
apply plugin: 'com.huawei.agconnect'
apply plugin: 'com.huawei.agconnect.apms'
Code:
implementation 'com.huawei.agconnect:agconnect-core:1.4.2.301'
implementation 'com.huawei.agconnect:agconnect-apms:1.4.1.303'
6. Add dependencies in build script repositories and all project repositories and class path in BaseProjectTemplate.
Code:
maven { url 'https://developer.huawei.com/repo/' }
classpath 'com.huawei.agconnect:agconnect-apms-plugin:1.4.1.303'
classpath 'com.huawei.agconnect:agcp:1.4.2.301'
7 Create Empty Game object rename to GameManager, UI canvas texts and button and assign onclick events to respective text and button as shown below.
8. Click to Build apk, choose File > Build settings > Build to Build and Run, choose File > Build settings > Build And Run.
GameManager.cs
C#:
using System.Diagnostics;
using UnityEngine;
using Debug = UnityEngine.Debug;
using HuaweiService.apm;
public class GameManager : MonoBehaviour
{
CustomTrace customTrace;
void Start()
{
customTrace = APMS.getInstance().createCustomTrace("testTrace");
}
public void onClickButton(){
customTrace.start();
Debug.Log ("Hello" + " world");
UnityEngine.Debug.Log("CustomTraceMeasureTest start");
customTrace.putMeasure("ProcessingTimes", 0);
for (int i = 0; i < 155; i++) {
customTrace.incrementMeasure("ProcessingTimes", 1);
}
long value = customTrace.getMeasure("ProcessingTimes");
Debug.Log("Measurename: ProcessingTimes, value: "+ value);
UnityEngine.Debug.Log("CustomTraceMeasureTest success");
}
}
Result
To view AppGallery Connect analysis choose Quality > APM
Tips and Tricks
Add agconnect-services.json file without fail.
Make sure dependencies added in build files.
Make sure that you that APM Service enabled.
Conclusion
In this article, we have learnt integration of Huawei Application Performance Management (APM) Service into Unity Game development using official plugin. Conclusion is APM helps us to rectify quickly and accurately app performance and continuously improve user experience.
Thank you so much for reading article, I hope this article helps you.
Reference
Unity Manual
Service Introduction official documentation
Checkout in forum

Categories

Resources