More information like this, you can visit HUAWEI Developer Forum
The capability to push messages to users is especially important for improving app engagement. However, it may be difficult to know what users want using conventional push methods, which do not tell you about the status of a user, and as a result, your push messages may fail to attract the attention of users or, even worse, may simply annoy them.
Wouldn't it be good if there was a way to learn about the status of a user in order to push custom content?
HUAWEI Push Kit 5.0 provides scenario-based messaging, which may help you address this pain point. The function identifies user status and displays content that users are interested in at the proper time and in the proper scenarios.
The following uses a demo to describe how to quickly push messages based on specific scenarios. This demo is open source and the source code can be downloaded from
https://github.com/HMS-Core/hms-push-clientdemo-android
1. Development Practice
1. Integrating the HMS Core Push SDK 5.0
1.1 Getting Started
1.1.1 Adding the AppGallery Connect Configuration File of Your App
Download the agconnect-services.json file.
{
"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"
}
Move the downloaded agconnect-services.json file to the app directory of your Android Studio project.
1.2 Configuring the Maven Repository Address for the HMS Core SDK
Open the build.gradle file in the root directory of your Android Studio project.
Add the AppGallery Connect plugin and the Maven repository.
Code:
buildscript {
repositories {
google()
jcenter()
maven {url 'https://developer.huawei.com/repo/'}
}
dependencies {
classpath 'com.huawei.agconnect:agcp:1.3.1.300'
}
}
allprojects {
repositories {
google()
jcenter()
maven {url 'https://developer.huawei.com/repo/'}
}
}
1.1.3 Adding Build Dependencies
Open the build.gradle file in the app directory.
Add build dependencies in the dependencies section.
Code:
dependencies {
implementation 'com.huawei.hms:push:5.0.0.300'
}
Add the following information under apply plugin: 'com.android.application' in the file header:
Code:
apply plugin: 'com.huawei.agconnect'
1.1.4 Configuring the AndroidManifest.xml File
Define the DemoHmsMessageService class (the class name is only for reference and can be customized) by inheriting from HmsMessageService, and implement its methods.
Code:
android
:name=
".DemoHmsMessageService"
android
:exported=
"false"
>
android
:name=
"com.huawei.push.action.MESSAGING_EVENT"
/>
1.1.5 Configuring Obfuscation Scripts
Open the obfuscation configuration file proguard-rules.pro of your project.
Code:
-ignorewarning -keepattributes *Annotation* -keepattributes Exceptions -keepattributes InnerClasses -keepattributes Signature -keepattributes SourceFile,LineNumberTable -keep class com.hianalytics.android.**{*;} -keep class com.huawei.updatesdk.**{*;} -keep class com.huawei.hms.**{*;}
The preceding describes key integration steps. For more details, please refer to the Push SDK 5.0 development guide, which you can access from the following link:
https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/android-config-agc-0000001050170137
Ensure that Push Kit is available before going to the next step.
2. Scenario-based Messaging
The scenarios include:
1. Holidays and weekends
2. Temperature (hot, comfortable, or cold)
3. UV intensity
4. DND canceled
5. Headset inserted or Bluetooth car kit disconnected
After completing the basic integration, you only need to add four lines of code and apply for the relevant user permission to implement scenario-based messaging.
· Apply for location permission in the holiday/weekend, UV intensity, and temperature scenarios. In addition, enable location permission for HMS Core and your app.
Code:
android
:name=
"android.permission.ACCESS_FINE_LOCATION"
/>
android
:name=
"android.permission.ACCESS_BACKGROUND_LOCATION"
/>
android
:name=
"android.permission.ACCESS_COARSE_LOCATION"
/>
· Apply for Bluetooth permission for headset inserted or Bluetooth car kit disconnected.
Code:
android
:name=
"android.permission.BLUETOOTH"
/>
The preceding operations may involve applying for new user permission. You may therefore need to update the privacy statement of your app and add usage description for the new user permission.
The HMS Core and Push Service version requirements for scenario-based messaging are as follows.
You'll need to perform testing on devices that satisfy the above version requirements.
Once you've completed all of the above, you are now ready to create a task on the Push Kit console.
3. Operations on the Push Kit Console
Step 1: Sign in to AppGallery Connect, select My projects, find your project from the project list, and click the app for which you need to create a task.
Step 2: Go to Project Setting > Growing > Push Kit > Automated notifications(Beta) and click New scenario push task to create a push task.
Step 3: Set relevant parameters.
Step 4: Select a scenario.
Step 5: Click Submit.
After the task is created, the task status changes to Sent, indicating that the task has been delivered to the device.
It takes about 10 minutes to create a scenario-based task. When a scenario triggering condition is met, the message will be displayed on the user device.
4. Display Effect
In the screenshot above, targeted messaging is implemented based on the headset inserted or Bluetooth car kit disconnected scenario. You are welcome to explore more messaging scenarios to ensure you send your users the proper messages at the proper time and in the proper scenarios.
For more information about HUAWEI Push Kit, visit
https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/service-introduction-0000001050040060
It's really worth trying
Related
More information like this, you can visit HUAWEI Developer Forum
Original link: https://forums.developer.huawei.com/forumPortal/en/topicview?tid=0202333697950470040&fid=0101187876626530001
Introduction
Dynamic Tag Manager allows the developers to deploy and configure information securely on web-based UI. It helps to track the user activities.
Use cases
1. Deliver an ad advertising app to the ad platform.
2. When user taps the ad download app and use.
3. Using DTM configure the rules and release configuration.
4. Automatically app updates the configuration.
5. Daily monitoring reports.
Advantages
1. Faster configuration file updates.
2. More third-party platforms.
3. Free-of-charge
4. Enterprise-level support and service
5. Simple and easy-to-use UI
6. Multiple data centers around the world
Steps
1. Create App in Android.
2. Configure App in AGC.
3. Integrate the SDK in our new Android project.
4. Integrate the dependencies.
5. Sync project.
Dynamic Tag Manager Setup
1. Open AppGallery Connect, select DTM Application and select Dynamic Tag Manager.
Choose My Projects > Growing >Dynamic Tag Manager
{
"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"
}
2. Click Create Configuration, enter required information in displayed dialogue-box and click OK.
3. Click Configuration name.
4. Click Configure, enter required details in Preset variables and Custom variables.
Click Name and click Variable tab to find Preset variables and Custom variables nodes.
Note: Preset variables is predefined variables and Custom variables is user defined variables.
5. A condition is the prerequisite for triggering a tag when the tag is executed. Click Create Condition tab, click Create to enter Name, Type and Trigger, and then click Save.
6. Click Create, enter the Name, Extensions and Operation in Configure tab.
Note: Tag is used to track events
7. Click Version tab and click Create.
Enter Name and Description, and then click OK.
Note: A version is a snapshot of a configuration at a time point, it can be used to record different phases of configuration.
8. Click a version in Version tab, to find Version details such as Overview and Operation records.
9. Click Download/Export version details paste into assets/containers folder.
Integration
App level gradle dependencies.
Code:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
Dtm kit dependencies
Code:
implementation 'com.huawei.hms:hianalytics:5.0.1.300'
implementation 'com.huawei.hms:dtm-api:5.0.0.302'
Kotlin dependencies
Code:
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
Root level gradle dependencies
Code:
maven {url 'http://developer.huawei.com/repo/'}
classpath 'com.huawei.agconnect:agcp:1.3.1.300'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
Add the below permissions in Android Manifest file
Code:
<manifest xlmns:android...>
...
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application ...
</manifest>
After configurations successfully done create instance for HiAnalyticsInstance in activity
Code:
private var mInstance: HiAnalyticsInstance? = null
mInstance = HiAnalytics.getInstance(this)
HiAnalyticsTools.enableLog()
Below snippet for the event trigger method.
Code:
fun updateEvent() {
val bundle = Bundle()
bundle.putString("user_name", userName.editText?.text.toString())
bundle.putString("user_mail", userMail.editText?.text.toString())
bundle.putString("user_number", userNumber.editText?.text.toString())
mInstance!!.onEvent("USERDINFO", bundle)
}
Using debug you can monitor real time data follow steps to enable debug mode.
Command for enabling the debug mode: adb shell setprop debug.huawei.hms.analytics.app <package_name>
Command for disabling the debug mode: adb shell setprop debug.huawei.hms.analytics.app .none.
After debug mode is enabled, all events
Result:
Reference:
To know more about DTM kit, check below URL.
https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/introduction-0000001050043907
More information like this, you can visit HUAWEI Developer Forum
1. What's Image Kit?
In an era of ubiquitous social media, and instantly sharable images, photo editing apps have become fixtures on so many user's phones. HUAWEI Image Kit endows apps with powerful smart editing and scene-specific animation capabilities, offering up to 24 ready-made image rendering effects and design functions.
By integrating the Kit, your app will be equipped to provide the enthralling, and enriching photo editing that today's users demand.
2. Function Demonstration and Sample Code
You can view the demo below to better understand what Image Kit may bring to you:
{
"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"
}
If you are interested in how to implement filters with Image Kit, download the source code from Github at the following address and optimize the code based on your application scenarios.
Github address: https://github.com/HMS-Core/hms-image-vision
1. Getting Started
Step 1: Configure app information in AppGallery Connect.
To integrate HUAWEI Audio Kit, you must complete the following preparations:
Register as a Huawei developer.
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.
Configure the Maven repository address and AppGallery Connect gradle plug-in.
Configure the signature file in Android Studio.
For details, please refer to Preparations for Integrating HUAWEI HMS Core.
Step 2: Start Android Studio.
Step 3: Choose File > Open, go to the directory where the sample project is decompressed, and click OK.
Step 4: Configure the AppGallery Connect plug-in, Maven repository address, build dependencies, obfuscation scripts, and permissions. (These items have been configured in the sample code. If any of them does not meet your requirements, change it in your own project.)
1. Configure the Maven repository address and AppGallery Connect plug-in in the project's build.gradle file.
Go to allprojects > repositories and configure the Maven repository address for the HMS Core SDK.
Code:
allprojects {
repositories {
maven { url 'https://developer.huawei.com/repo/' }
…
}
}
Go to buildscript > repositories and configure the Maven repository address for the HMS Core SDK.
Code:
buildscript {
repositories {
maven {url 'https://developer.huawei.com/repo/'}
…
}
…
}
Go to buildscript > dependencies and add dependency configurations.
Code:
buildscript{
dependencies {
classpath 'com.huawei.agconnect:agcp:1.3.1.300'
}
}
2. Configure the dependency package in the app's build.gradle file.
Add a dependency package to the dependencies section in the build.gradle file.
Code:
dependencies {
…
implementation 'com.huawei.hms:image-vision:1.0.2.301'
…
}
Configure minSdkVersion.
Code:
android {
...
defaultConfig {
...
minSdkVersion 26
...
}
...
}
Add the AppGallery Connect plug-in dependency to the file header.
Code:
apply plugin: 'com.huawei.agconnect'
Note: Make sure that you configure apply plugin: 'com.huawei.agconnect' after apply plugin:'com.android.application'.
3. Configure obfuscation scripts.
Configure the following information in the app/proguard-rules.pro file:
Code:
-ignorewarnings
-keepattributes *Annotation*
-keepattributes Exceptions
-keepattributes InnerClasses
-keepattributes Signature
-keepattributes SourceFile,LineNumberTable
-keep class com.hianalytics.android.**{*;}
-keep class com.huawei.updatesdk.**{*;}
-keep class com.huawei.hms.**{*;}
If you are using AndResGuard, add it to the trustlist in the obfuscation configuration file.
Code:
"R.string.hms*",
"R.string.connect_server_fail_prompt_toast",
"R.string.getting_message_fail_prompt_toast",
"R.string.no_available_network_prompt_toast",
"R.string.third_app_*",
"R.string.upsdk_*",
"R.layout.hms*",
"R.layout.upsdk_*",
"R.drawable.upsdk*",
"R.color.upsdk*",
"R.dimen.upsdk*",
"R.style.upsdk*",
"R.string.agc*"
4. Configure permissions in the 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_WIFI_STATE" />
Step 5: In the Android Studio window, choose File > Sync Project with Gradle Files to synchronize the project.
This is not the end. For full content, you can visit https://forums.developer.huawei.com/forumPortal/en/topicview?tid=0202349402887660146&fid=0101187876626530001
Hi Some times am facing init authJson error did you face this kind of error? if you have any solution provide me.
In this article, I am going to create a Flutter project –actually a tiny game- and explain how to implement Analytics Kit. But first, let me inform you about Huawei Analytics Kit a little.
{
"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 Analytics Kit
Huawei Analytics Kit offers you a range of analytics models that help you not only to analyze users’ behavior with preset and custom events, but also gain an insight into your products and contents. So that you can improve your skills about marketing your apps and optimizing your products.
HUAWEI Analytics Kit identifies users and collects statistics on users by anonymous application identifier (AAID). The AAID is reset in the following scenarios:
1) Uninstall or reinstall the app.
2) The user clears the app data.
After the AAID is reset, the user will be counted as a new user.
HUAWEI Analytics Kit supports event management. For each event, maximum 25 parameters; for each app maximum 100 parameters can be defined.
There are 3 types of events: Automatically collected, predefined and custom.
Automatically collected events are collected from the moment you enable the kit in your code. Event IDs are already reserved by HUAWEI Analytics Kit and cannot be reused.
Predefined events include their own Event IDs which are predefined by the HMS Core Analytics SDK based on common application scenarios. The ID of a custom event cannot be the same as a predefined event’s ID. If so, you will create a predefined event instead of a custom event.
Custom events are the events that you can create for your own requirements.
More info about the kit and events.
Configuration in AppGallery Connect
Firstly, you will need a Huawei developer account. If you don’t have one, click here and register. It will be activated in 1–2 days.
After signing in to AppGallery Connect, you can add a new project or select an existing project. In the project you choose, add an app. While adding app, make sure you enter the package name right. It should be the same as your Flutter project’s package name.
Also, make sure you set data storage location, enable Analytics kit and add SHA-256 fingerprint to AppGallery Connect.
How to generate SHA-256 Fingerprint?
In Android Studio, right click on android folder under your project and select Flutter > Open Android module in Android Studio.
On the right panel, select Gradle and follow the steps that are shown in the picture below. Open signingReport and there is your SHA-256 fingerprint.
Copy the code and paste it on the project settings in the AppGallery Connect.
Integrate HMS to your project
Download agconnect-services.json file and place it under project_name > android > app.
Add Signing Configuration
Create a file named key.properties under android folder and add your signing configs here.
Code:
storeFile file(‘<keystore_file>.jks’)
storePassword ‘<keystore_password>’
keyAlias ‘<key_alias>’
keyPassword ‘<key_password>’
Define your key.properties file by adding the code below, before android block in your app-level build.gradle file.
Code:
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file(‘key.properties’)
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
TO-DOs in project-level build.gradle
Code:
buildscript {
repositories {
google()
jcenter()
maven {url 'http://developer.huawei.com/repo/'} //add this line
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.huawei.agconnect:agcp:1.1.1.300' //add this line
}
}
allprojects {
repositories {
google()
jcenter()
maven {url 'http://developer.huawei.com/repo/'} //add this line
}
}
TO-DOs in app-level build.gradle
Code:
defaultConfig {
...
minSdkVersion 19 //Increase this to 19
}
//Add these lines
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
//Edit buildTypes
buildTypes {
debug {
signingConfig signingConfigs.release
}
release {
signingConfig signingConfigs.release
}
}
//Add dependencies
dependencies {
implementation 'com.huawei.agconnect:agconnect-core:1.0.0.300'
implementation 'com.huawei.hms:hianalytics:5.0.1.300'
}
apply plugin: 'com.huawei.agconnect' //Add this line to the bottom of the page
Add Analytics Kit to your project
There are 2 ways to do this step.
1) Go to developer website and download plugin. In Android Studio create a new folder in your root directory and name it “hms”. Unzip the plugin and paste it in “hms” folder.
Then, go to pubspec.yaml and add the plugin under dependencies.
2) This way is much easier and also more familiar to Flutter developers. In pub.dev copy the plugin and add it under dependencies as usual.
For both ways, after running pub get command, the plugin is ready to use!
For more information about HMS Core integration, click.
We are all done. Let’s begin coding.
I will make a tiny and very easy game that I belive most of you know the concept: Guess the number!
As you play the game and try to guess the number, Huawei Analytics Kit will collect statistics how many times you guessed.
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 ?
{
"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, I will be integrating Huawei Push Kit in an Application.
Push Kit
Push notifications offers a great way to increase your application’s user engagement and boost your retention rates by sending meaningful messages or by informing users about your application. Push Kit supports two types of messages: notification messages and data messages. You can send notifications and data messages to your users from your server using the Push Kit APIs or directly from the AppGallery Push Kit Console.
Requirements
1. Any operating system (MacOS, Linux and Windows).
2. Must have a Huawei phone with HMS 4.0.2.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. Minimum API Level 21 is required.
5. Required EMUI 9.0.0 and later version devices.
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. Choose View > Tool Windows > Gradle > Signingreport > SHA256 code.
Or use cmd as explained in SHA256 CODE
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.
7. Enter SHA-256 certificate fingerprint and click Save.
8. Click Manage APIs tab and enable Push Kit.
9. Add the below maven URL in build.gradle(Project) file under the repositories of buildscript, dependencies and allprojects, refer Add Configuration.
Code:
maven { url 'http://developer.huawei.com/repo/' }
classpath 'com.huawei.agconnect:agcp:1.6.0.300'
10. Add the below plugin and dependencies in build.gradle(Module) file.
Code:
apply plugin: id 'com.huawei.agconnect'
//Huawei AGC
Code:
implementation 'com.huawei.agconnect:agconnect-core:1.6.0.300'
// Huawei Push Kit
Code:
implementation 'com.huawei.hms:push:6.3.0.302'
11. Now Sync the gradle.
12. Add the required permission to the Manifestfile.xml file.
Code:
// Push Kit
<uses-permission android:name="android.permission.INTERNET" />
<service
android:name=".PushService"
android:exported="false">
<intent-filter>
<action android:name="com.huawei.push.action.MESSAGING_EVENT" />
</intent-filter>
</service>
Sometimes adding everything manually can be burden. Let’s use Configuration Wizard for the setup.
Configuration Wizard
Now, we will help how to use configuration wizard of HMS Toolkit to automatically complete necessary configuration for development preparations.
Watch this video to understand how to use the configuration Wizard.
Once all the items are passed, you are good to go.
Integrating Push Kit Through Coding Assistant
Navigate to HMS > Coding Assistant, and select Push Kit in the kit list. The following figure shows all the scenarios of Push Kit.
Completing the Code by Dragging and Dropping Scenario Cards.
Select a scenario card for development, for example, Send notification message-Open home pages of corresponding apps, and drag and drop the card to the code area to generate the code for obtaining a push token
Using a Tool to Send Messages
On the toolbar of the Push Kit card, select Message Test to test whether the server can push messages to the device.
Click Get APP ID and APP SECRET. The tool automatically reads the app ID and app secret from AppGallery Connect. Click Next.
On the page that is displayed, set parameters as prompted or based on the following table.
After the setting, click Send.
Result
After successful message sending, you will receive a notification message on your device.
Tips and Tricks
1. Set minSDK version to 24 or later, otherwise you will get AndriodManifest merge issue.
2. Make sure you have added the agconnect-services.json file to app folder.
3. Make sure you have added SHA-256 fingerprint without fail.
4. Make sure all the dependencies are added properly.
Conclusion
In this article, we have learnt integration of Push Kit in application. It will guide you to increase your application’s user engagement and boost your retention rates by sending meaningful messages or by informing users about your application.
Reference
Push Kit: Documentation
Push Kit: Training Video