How to download and Integrate the HUAWEI Account Kit SDK [Eclipse IDE] - Huawei Developers

1. Eclipse SDK Download
If you are using the Eclipse IDE, download the HMS SDK package and integrate it locally.
Integrating the HMS SDK into Your App Project in the Eclipse IDE
Before starting your development in the Eclipse Integrated Development Environment (IDE), download the HMS SDK and integrate it into your app project.
Downloading the SDK
1. Download and decompress the zip packages of the HMS Base SDK and HUAWEI Account SDK.
For details, please refer to Eclipse SDK Download.
2. Import all SDK projects to your workspace.
a. Go to File > Import > Android > Existing Android Code Into Workspace and click Next.
{
"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"
}
b. Click Browse and navigate to the directory where your projects are located. Select the projects to be imported under Projects and click Finish. By default, all projects are selected. You can change as needed.
NOTE:The projects to be imported must be located in the same drive as the workspace, for example, D:\. If they are not in the same drive, select Copy projects into workspace to copy the project file to the workspace.
Adding Project Dependencies
1. Right-click your app project and choose Properties from the shortcut menu.
2. Choose Android from the navigation tree, click Add, select the imported projects, and click OK.
3. As the XML file in the Eclipse IDE does not support the dollar sign ($), replace ${applicationId} in the AndroidManifest.xml file of the HMSSdkBase and Agconnect-core projects with your app package name
Code:
<application>
<provider
android:name="com.huawei.agconnect.core.provider.AGConnectInitializeProvider"
android:authorities="${applicationId}.AGCInitializeProvider"
android:exported="false" />
<service
android:name="com.huawei.agconnect.core.ServiceDiscovery"
android:exported="false" />
</application>
Copying the HMSSdkBase Properties Files to Your App Project Directory
Copy the properties files in the assets directory of the HMSSdkBase project to the assets directory of your app project.
NOTE: If any other kits are involved, copy the properties files of these kits to your app project directory.
Configuring the project.properties File
Find and open the file in your project directory and add the following code to merge the manifest files in the subprojects:
Code:
manifestmerger.enabled=true
Adding the AppGallery Connect Configuration File
1. Sign in to AppGallery Connect and select My apps.
2. Find your app from the list and click the app name.
3. Go to Develop > Overview > App information.
4. Click agconnect-services.json to download the configuration file.
5. The Eclipse IDE does not support the AppGallery Connect plug-in. Therefore, you need to place the agconnect-services.json file in the assets directory of your project and add the following code to the Application subclass of the project. If the project does not have an Application subclass, you need to create a subclass that is inherited from the Application subclass. For example, create a MyApplication class.
Code:
public class MyApplication extends Application{
@Override
public void onCreate() {
super.onCreate();
}
// TODO: Add the following code:
@Override
protected void attachBaseContext(Context context) {
super.attachBaseContext(context);
AGConnectServicesConfig config = AGConnectServicesConfig.fromContext(context);
config.overlayWith(new LazyInputStream(context) {
public InputStream get(Context context) {
try {
return context.getAssets().open("agconnect-services.json");
} catch (IOException e) {
return null;
}
}
});
}
// TODO: End
}
You still need to import the following classes:
Code:
import java.io.IOException;
import java.io.InputStream;
import com.huawei.agconnect.config.AGConnectServicesConfig;
import com.huawei.agconnect.config.LazyInputStream;
import android.app.Application;
import android.content.Context;
import android.util.Log;
6. Open the AndroidManifest.xml file of your project and add the Application subclass name to the application section. If the subclass name has been added, skip this step. In the following example, add the MyApplication class name.
Code:
<application
android:name=".MyApplication"
…
>
…
</application>
7. In the Eclipse IDE menu bar, click Project, then Clean.

Related

Delimiting Huawei Account Kit feat. React Native

More information like this, you can visit HUAWEI Developer Forum​
Original link: https://forums.developer.huawei.com/forumPortal/en/topicview?tid=0201346110142010150&fid=0101187876626530001
HUAWEI Account Kit offers very simple, quick and secure sign in and authorization functionalities which help developers to implement hassle free and quick sign in functionalities for applications.
HUAWEI Account Kit offers services on different parameters as
Quick and Standard
Massive user base and global services
Secure, reliable, and compliant with international standards
Quick sign-in to apps
Development Overview
Prerequisite
1. Must have a Huawei Developer Account
2. Must have a Huawei phone with HMS 4.0.0.300 or later
3. React Native environment with Android Studio, Node Js and Visual Studio code.
Major Dependencies
1. React Native CLI : 2.0.1
2. Gradle Version: 6.0.1
3. Gradle Plugin Version: 3.5.2
4. React Native Account Kit SDK : 5.0.0.300
5. React-native-hms-account kit gradle dependency
6. AGCP gradle dependency
Preparation
1. Create an app or project in the Huawei app gallery connect, click My apps, as shown below.
{
"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"
}
1.0 Click on New app.
2. Provide the SHA Key and App Package name of the project in App Information Section and enable the required API.
2.0 Add the below information to create a new app and project
2.1 Once app is created, navigate to My projects
2.2 Click on the created project, as shown below.
2.3 Enable the AccountKit API
2.4 Put SHA signature generated using Android Studio
2.5 Download agconnect-services.json services file and paste it under App folder of the project.
3. Create a react native project, use the below command
Code:
“react-native init project name”
4. Download the React Native Account Kit SDK and paste it under Node Modules directory of React Native project.
Tips
1. Run below command under project directory using CLI if you cannot find node modules.
Code:
“npm install” & “npm link”
Integration
1. Configure android level build.gradle
Add to buildscript/repositories and allprojects/repositories
Code:
maven {url 'http://developer.huawei.com/repo/'}
2. Configure app level build.gradle. (Add to dependencies)
Code:
Implementation project (“:react-native-hms-account”)
3. Linking the HMS Account Kit Sdk.
Run below command in the project directory
Code:
react-native link react-native-hms-account
Adding permissions
Add below permissions to Android.manifest file.
Code:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Development Process
Once sdk is integrated and ready to use, add following code to your App.js file which will import the API’s present.
Import the SDK
Silent Sign In
On Cancel Authorization
On Adding Authorization Scopes
Retrieve SMS Verification Code
Testing
Import the SDK
Add below line of code in the app.js file
Code:
import RNHMSAccount from "react-native-hms-account";
Silent Sign In
With silent sign in, the users can sign in without using their login credientials for consecutive sign-ins. To silent sign in, invoke the silentSignIn method of the HMSAccount module. The promise is resolved if the silent sign in is successful, is rejected otherwise.
Add below code on the “SILENT SIGN IN” button click
Code:
const onSilentSignIn = () => {
RNHMSAccount.HmsAccount.silentSignIn()
.then((response) => {
logger(JSON.stringify(response));
})
.catch((err) => {
logger(err);
});
};
On Cancel Authorization
Cancelling authorization is intended to increase security by forcing the users to use login credentials while signing in. To cancel authorization, invoke the cancel Authorization method of the HMSAccount module. The promise is resolved if the silent sign in is successful, is rejected otherwise.
Add below code on the “ONCANCELAUTHORIZATION” button click.
Code:
const onCancelAuthorization = () => {
RNHMSAccount.HmsAccount.cancelAuthorization()
.then((response) => {
logger(JSON.stringify(response));
})
.catch((err) => {
logger(err);
});
};
On Adding Authorization Scopes
Auth Manager class is responsible for creating the authorization scopes to build the data.
Add below code on the “ONADDAUTHSCOPES” button click.
Code:
const onAddAuthScopes = () => {
let buildData = {
requestCode: 888,
scopes: [RNHMSAccount.HmsAccount.SCOPE_ID_TOKEN],
};
RNHMSAccount.HuaweiIdAuthManager.addAuthScopes(buildData)
.then((response) => {
logger(JSON.stringify(response));
})
.catch((err) => {
logger(err);
});
};
Retrieve SMS Verification Code
Read SMS manager is a service to listen verification code SMS events. To start read SMS manager, invoke the startReadSMSManager method of the module.
Code:
const onStartReadSMSManager = () => {
RNHMSAccount.SMSManager.startReadSMSManager()
.then((response) => {
logger(JSON.stringify(response));
})
.catch((err) => {
logger(err);
});
};
Testing
Run the below command to build the project
Code:
React-native run-android.
After successful build, run the below command in the android directory of the project to create the signed apk.
Code:
gradlew assembleRelease
Results
References
https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/introduction-0000001050725712
Conclusion
Adding Account kit functions seem easy.

Integration of ML Kit into Ionic Application (Face-Related Service) - Part 4

In my previous articles, we learn how to integrate Huawei ML Kit Text-related, Language-related and Image-related services. Today we are going to explore Face/Body-related service of Huawei machine learning kit.
Introduction
Huawei ML kit Face/Body-related service is used for detecting the shapes and features of our face, hand and body which includes facial expression, age, gender, hand points and many more. Use this service by creating an application which beautify user face when they are in video call or astrology & horoscope application by predicting future using hand key point detection service.
Face/Body-related services
As of now there is only one Cordova plugin developed for Face/Body- related services and that is Face Detection. Here we will use this service to showcase the power HMS ML Kit in Ionic application.
Demo
{
"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"
}
Prerequisite
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.
4) Must install node in the system
5) Must install Ionic in the system using below command:
Code:
npm install -g [user=1329689]@iONiC[/user]/cli
Things need to be done
1) Generating a Signing Certificate Fingerprint. For generating the SHA key, refer this article.
2) Create an app in the Huawei AppGallery connect and enable ML Kit in Manage API section.
3) Provide the SHA Key in App Information Section.
4) Provide storage location.
5) Download the agconnect-services.json and store it somewhere on our computer.
6) Create a blank Ionic Project using below command:
Code:
ionic start Your_Application_Name blank --type=angular
7) Download the Cordova Ml Kit Plugin. Run the following command in the root directory of your Ionic project to install it through npm.
Code:
npm install <CORDOVA_MLKIT_PLUGIN_PATH>
8) If you want full Ionic support with code completion etc., install @iONiC-native/core in your project.
Code:
npm install [user=1329689]@iONiC[/user]-native/core --save-dev
9) Run the following command to copy the "ionic/dist/hms-ml" folder from library to "node_modules @iONiC-native" folder under your Ionic project.
Code:
cp node_modules/@hmscore/cordova-plugin-hms-ml/ionic/dist/hms-ml node_modules [user=1329689]@iONiC[/user]-native/ -r
10) Run the following command to compile the project:
Code:
ionic build
npx cap init [appName] [appId]
Where appName is the name of your app, and appId is package_name in your agconnect-services.json file (example: com.example.app).
11) Run the following command to add android platform to your project:
Code:
ionic capacitor add android
12) Make sure your project has a build.gradle file with a maven repository address and agconnect service dependencies as shown below:
13) Add the Signing certificate configuration to the build.gradle file in the app directory as show below:
14) Add plugin to the build.gradle file in the app directory as show below:
15) Add ads service implementation into to dependencies section of build.gradle file in the app directory as show below:
16) Add agconnect-services.json and signing certificate jks file to the app directory in your Android project as show below:
17) To update dependencies, and copy any web assets to your project, run the following code:
Code:
npx capacitor sync
Let's Code
Install FileChooser
We need to install FileChooser to select a file or in this case an image, returns a file URI. Run the following command on visual studio terminal:
Code:
npm install cordova-plugin-filechooser
npm install [user=1329689]@iONiC[/user]-native/file-chooser
ionic cap sync
Android Permission
We need android permission in order to allow our users to give their permission to the application like camera permission, storage permission etc. Run the following command on visual studio terminal:
Code:
npm install cordova-plugin-android-permissions
npm install [user=1329689]@iONiC[/user]-native/android-permissions
ionic cap sync
Avoid No Provider Error
To avoid No Provider Error, we need to add FileChooser, Android Permission and HMS ML kit in app.module.ts providers section and also make sure to import the same as shown below:
Code:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import { IonicModule, IonicRouteStrategy } from [user=1329689]@iONiC[/user]/angular';
import { SplashScreen } from [user=1329689]@iONiC[/user]-native/splash-screen/ngx';
import { StatusBar } from [user=1329689]@iONiC[/user]-native/status-bar/ngx';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { AndroidPermissions } from [user=1329689]@iONiC[/user]-native/android-permissions/ngx';
import { FileChooser } from [user=1329689]@iONiC[/user]-native/file-chooser/ngx';
import { HMSMLKit } from [user=1329689]@iONiC[/user]-native/hms-ml/ngx'
import { FilePath } from [user=1329689]@iONiC[/user]-native/file-path/ngx';
@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule],
providers: [
StatusBar,
SplashScreen,
AndroidPermissions,
FileChooser,
HMSMLKit,
FilePath,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
],
bootstrap: [AppComponent]
})
export class AppModule {}
More details about this, you can check https://forums.developer.huawei.com/forumPortal/en/topicview?tid=0202387591680950486&fid=0101187876626530001

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

Coding-free Integration of AppGallery Connect Crash into a Unity App?

Reference:
https://docs.unity.cn/cn/Packages-cn/[email protected]/manual/crash.html
1. Download Unity Hub.
2. Configure the Android environment in Unity Editor.
Choose Edit > Preferences > External Tools > Andriod and configure the JDK and SDK paths. You can keep the default paths.
Choose Edit > Project Settings > Player > Publish Settings. In the Build area, select items for Android as required.
{
"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"
}
3. Import the HuaweiService package.
Download the package from Unity Assets Store.
In Unity Editor, choose Assets > Import package.
Select the required package and click Import. If you’re not sure which one to use, you can select all of them.
Completing Configurations in AppGallery Connect
1. Sign in to AppGallery Connect, and click the created app.
2. Go to My projects > Quality > Crash and click Enable now to enable the Crash service.
3. Go to Project settings > General information and download the latest agconnect-services.json file.
4. Save the file to the Assets\Plugins\Android directory of your Unity project.
Configuring the Project Information in Unity Editor
1. In Unity Editor, choose Edit > Project Settings > Player > Other Settings, and set the package name to match the package name you set in AppGallery Connect.
2. Add the following code to the project-level baseProjectTemplate.gradle file in the Assets\Plugins\Android directory:
XML:
allprojects {
buildscript {
repositories {
maven { url 'https://developer.huawei.com/repo/' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.0'
classpath 'com.huawei.agconnect:agcp:1.4.2.300'
}
}
repositories {
maven { url 'https://developer.huawei.com/repo/' }
}
}
3. Add the following code to the app-level LauncherTemplate.gradle file in the Assets\Plugins\Android directory:
XML:
apply plugin: 'com.android.application'
apply plugin: 'com.huawei.agconnect'
dependencies {
implementation 'com.huawei.hms:hianalytics:5.0.5.300'
implementation 'com.huawei.agconnect:agconnect-crash:1.4.2.300'
}
Integrating the Crash Service
1. In Unity Editor, choose GameObject > UI > Button and create a button. Click the button, click Add Component on the right to create a script file called testcrash, and then add the following methods:
C#:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HuaweiService;
using HuaweiService.crash;
public class testcrash : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void CrashCollectON()
{
AGConnectCrash.getInstance().enableCrashCollection(true);
}
public void CrashCollectOFF()
{
AGConnectCrash.getInstance().enableCrashCollection(false);
}
public void SetTestIt()
{
Application.ForceCrash(0);
}
public void SetUserId()
{
AGConnectCrash.getInstance().setUserId("TestUser");
}
public void SetCustomKey()
{
AGConnectCrash.getInstance().setCustomKey("stringKey", "Hello world");
AGConnectCrash.getInstance().setCustomKey("booleanKey", false);
AGConnectCrash.getInstance().setCustomKey("doubleKey", 1.1);
AGConnectCrash.getInstance().setCustomKey("floatKey", 1.1f);
AGConnectCrash.getInstance().setCustomKey("intKey", 0);
AGConnectCrash.getInstance().setCustomKey("longKey", 11L);
}
public void SetDefaultlog()
{
AGConnectCrash.getInstance().log("set default log");
}
public void Setlog()
{
AGConnectCrash.getInstance().log(3, "set debug log");
AGConnectCrash.getInstance().log(4, "set info log");
AGConnectCrash.getInstance().log(5, "set warning log");
AGConnectCrash.getInstance().log(6, "set error log");
}
}
Keep creating other buttons and associating corresponding methods with them.
CrashCollectON:Enables crash data reporting.
CrashCollectOFFisables crash data reporting.
SetTestIt:Creates a crash.
SetCustomKey:Sets a custom key-value pair.
SetDefaultlog:Sets the default log level.
Setlog:Sets a custom log level.
SetUser:Sets a custom user ID.
2. Package the APK file and launch the app. Check whether the buttons have been successfully created.
Testing the API and Viewing the Crash Report
I have written about this part before. Please check out my previous post for details.
Generating and Uploading a Mapping File
Manual upload
1. Open the obfuscation script file for your Unity project.
2. Create the proguard-unity.txt and proguard-user.txt files and add the following code to prevent obfusaction:
XML:
-keepattributes *Annotation*
-keepattributes SourceFile,LineNumberTable
-keep public com.crashlytics.** { *; }
3. When the APK package is generated, the corresponding mapping file is automatically generated accordingly. You can then upload the mapping file to AppGallery Connect.
Auto upload
1. Enable the automatic upload of the mapping file.
Add the following code to the app-level LauncherTemplate.gradle file in the Assets\Plugins\Android directory:
XML:
apply plugin: 'com.android.application'
apply plugin: 'com.huawei.agconnect'
agcp{
mappingUpload = true
debug = true
appVersion = '0.1'
}
dependencies {
implementation 'com.huawei.hms:hianalytics:5.0.5.300'
implementation 'com.huawei.agconnect:agconnect-crash:1.4.2.300'
}
2. Export your Unity project and open it in Android Studio.
3. Generate a mapping file, which is automatically uploaded.
Run the gradle clean assembleRelease command or use Android Studio to install the app. The mapping file will be successfully generated.
The following code indicates that the upload is successful.
Restoring the Obfuscated Report
The following figure is a crash report when the obfuscation mapping file has not been uploaded.
This figure shows what the report looks like after being restored.
For more details, please refer to:
Crash sample code:
https://github.com/AppGalleryConnect/agc-demos/tree/main/Android/agc-crash-demo-java

Send messages in App! Integrate Huawei In App Messaging services using React Native

{
"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
In this article, we will learn how to implement In App Messaging service provided by Huawei. App Messaging of AppGallery Connect to send relevant messages to target users actively using your app to encourage them to use key app functions, or send attractive promotion activities to enhance user loyalty.
Requirements
1. JDK version: 1.7 or later
2. Android Studio version: 3.X or later
3. minSdkVersion: 21 or later
4. targetSdkVersion: 31 (recommended)
5. compileSdkVersion: 29 (recommended)
6. Gradle: 4.1 or later (recommended)
7. Must have a Huawei Developer Account.
8. Must have a Huawei phone with HMS 4.0.0.300 or later and running EMUI 4.0 or later.
9. React Native environment with Android Studio, Node Js and Visual Studio code.
Preparation
1. Create an app or project in the Huawei App Gallery Connect.
2. Provide the SHA Key and App Package name of the project in App Information Section and enable the App Messaging API.
3. Download the agconnect-services.json file.
4. Create an Android project.
Integration process
Create a react native project using below command:
Code:
react-native init Project Name
Add below to build.gradle (project) file under buildscript/repositories and allprojects/repositories.
Code:
Maven {url 'http://developer.huawei.com/repo/'}
Add below to build.gradle(app) file, under dependencies to use the App Messaging Sdk.
dependencies{
// Import the App Messaging SDK.
Code:
implementation 'com.huawei.agconnect:agconnect-appmessaging:1.5.1.300'
Note>> to use the Analytics, please add Analytics SDK
Code:
implementation 'com.huawei.hms:hianalytics:5.2.0.300'
}
Add below permissions to manifest file.
Code:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name= "android.permission.ACCESS_NETWORK_STATE"/>
Open the build.gradle file in the android directory of your React Native project, and change the value of minSdkVersion in buildscript to 19.
Development Process
To make your app's orientation work by default, orientation keywords should be removed from android:configChanges property of the activity tag in AndroidManifest.xml file.
An example of your AndroidManifest.xml is as follows:
Code:
<!-- AndroidManifest.xml. -->
<activity
android:name="com.huawei.agc.rn.appmessaging.example.MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|screenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Import the following into APP.js file.
Code:
import AGCAppMessaging from '@react-native agconnect/appmessaging';
import {Alert} from 'react-native';
The React Native App Messaging plugin allows you to enable or disable data synchronization from the AppGallery Connect server. The function is enabled by default. The AGCAppMessaging.setFetchMessageEnable API can be called to enable or disable data synchronization from the AppGallery Connect server.
Code:
import AGCAppMessaging from '@react-native-agconnect/appmessaging';
import {Alert} from 'react-native';
AGCAppMessaging.setFetchMessageEnable(true).then(result => {
Alert.alert("[setFetchMessageEnable] " + JSON.stringify(result));
}).catch((err) => {
Alert.alert("[setFetchMessageEnable] Error/Exception: " + JSON.stringify(err));
});
The AGCAppMessaging.setDisplayEnable API can be called to set whether to enable message display.
Code:
import AGCAppMessaging from '@react-native-agconnect/appmessaging';
import {Alert} from 'react-native';
AGCAppMessaging.setDisplayEnable(false).then(result => {
Alert.alert("[setDisplayEnable] " + JSON.stringify(result));
}).catch((err) => {
Alert.alert("[setDisplayEnable] Error/Exception: " + JSON.stringify(err));
});
Add a listener to obtain app message events.
Code:
const eventEmitter = new NativeEventEmitter(AGCAppMessaging);
this.eventListener = eventEmitter.addListener(AGCAppMessaging.EventTypes.ON_MESSAGE_DISPLAY,
(event) => {
Alert.alert("[onMessageDisplay] " + JSON.stringify(event));
console.log("[onMessageDisplay] " + JSON.stringify(event));
})
Call the AGCAppMessaging.setForceFetch API in the testing code to specify that the in-app message data must be obtained from the AppGallery Connect server forcibly.
Sending App Message to our App Users
Choose Your Project in App-Gallery Connect and select the application which you want to test an in-app message of the project.
Choose Grow > App Messaging > New
Enter the information required to send App Messages.
On SELECT SENDING TARGET, Choose your application as Target and click Next.
Select Target users by referring to this document.
Now Set Schedule time and click Next.
Click on OK and then Publish.
Now navigate to Management > Operation column and click Test.
Click Add test user and enter the AAID of the test device in the text box. Click Save.
Now in your APP, Test whether the message can be properly displayed and operated.
Output
You can check the action in your console log
Tips and Tricks
1. Set minSdkVersion to 19 or higher.
2. To view the events of App Messaging, Huawei Analytics needs to be enabled and configured.
Conclusion
In this article, we have learned how to integrate IN APP Messaging service by Huawei. APP Messages are very useful for delivering the right message to the target user. It encourages them to use key app functions, or send attractive promotion activities to enhance user loyalty.
Reference
In App Messaging: Documentation
In App Messaging : Training Video

Categories

Resources