Introduction To HMS Core Push Kit
Introduction To HMS Core Push Kit
Notification messages
Data messages
02
Advantages of HMS Push Kit
Text style
Badges
Customized Style
Notification messages can be
displayed in various styles Button style
Ringtones
03 HMS Push Kit
Required Settings
Create an app or project in the Huawei app gallery connect.
Provide the SHA Key and App Package name of the android project in App Information Section.
Download the agconnect-services.json from App Information Section. Add the json file in the app
folder of the android project.
Add the maven url inside the repositories of buildscript and allprojects respectively (project
build.gradle file)
maven { url 'http://developer.huawei.com/repo/' }
Add the class path inside the dependency section of project build.gradle file.
classpath 'com.huawei.agconnect:agcp:1.4.1.300'
implementation 'com.huawei.hms:push:{version}
<service
android:name=".DemoHmsMessageService"
android:exported="false">
<intent-filter>
<action android:name="com.huawei.push.action.MESSAGING_EVENT"/>
</intent-filter>
</service>
The above code uses the DemoHmsMessageService class as an example (the class name is
customized).
The exported attribute must be set to false to prevent components of other apps from
enabling
the service.
04
Steps 1 and 2: An app integrated with the HMS SDK obtain a push token.
Steps 3: The app reports the obtained push token to the app server.
Steps 4: The app server uses the push token to call APIs of the HUAWEI Push Kit server to send
messages.
Steps 5: The HUAWEI Push Kit server sends the messages to devices and the devices receive the
messages. For details, Steps 6 and 7: When the HUAWEI Push Kit server detects responses from the
devices, it sends a message receipt to the app server.
After integrating the HMS Core Push SDK, apply for a token.
Each app has a unique push token on each device. The client calls the getToken method
in HmsInstanceId to obtain the token from the Push Kit server.
Then the app server sends messages to the app based on the token. You can upload tokens
to the token list on your app server for Sending messages. Your app server can then call the
push API of the Push Kit server to send messages to apps in batches based on the tokens.
private void getToken() {
// Create a thread.
new Thread() {
@Override
public void run() {
try {
// Obtain the app ID from the agconnect-service.json file.
String appId =
AGConnectServicesConfig.fromContext(MainActivity.this).getString("client/app_id");
// Enter the token ID HCM.
String tokenScope = "HCM";
String token = HmsInstanceId.getInstance(MainActivity.this).getToken(appId, tokenScope);
Log.i(TAG, "get token: " + token);
Override the onNewToken method. When a token changes or the EMUI version is earlier than
10.0, call the onNewToken method to return a token.
@Override
public void onNewToken(String token) {
// Obtain a token.
Log.i(TAG, "received refresh token:" + token);
<meta-data
android:name="push_kit_auto_init_enabled"
android:value="true"/>
• Method 2:
Explicitly call the setAutoInitEnabled (boolean enable) method in the MainActivity class. In the
method, the enable parameter indicates whether to enable automatic initialization. The
options are true (yes) and false (no).
The topic messaging function provided by Push Kit allows you to send messages to multiple
devices whose users have subscribed to a specific topic. You can write notification messages about
the topic as required, and Push Kit sends the messages to correct devices in a reliable manner.
For example, users of a weather forecast app can subscribe to the weather topic and receive
notification messages about weather.
What are the requirements for a phone to receive messages sent by the Push Kit server?
Device: A Huawei phone or a non-Huawei phone with HMS Core (APK) installed. The APK can be
downloaded from HUAWEI AppGallery.
Network: The phone is connected to the network and the connection is stable.
EMUI version: Some Huawei phones running EMUI 4.0 or EMUI 4.1 and all Huawei phones running EMUI
5.0 or a later version. EMUI 5.0 and later versions are recommended.
https://forums.developer.huawei.com/forumPortal/en/topic/0201211024056890110
Youtube Link:
https://www.youtube.com/watch?v=U1gy7Tvfepc
Thank You