After integrating the push SDK, you can clear notification badges, report vendor channel tokens, customize notification channels, and configure push channel priority.
Prerequisites
The
MPPushMsgServiceAdaptermethod in this topic requires baseline version 10.1.68.32 or later. To upgrade, see mPaaS Upgrade Guide.The
AliPushRcvServicemethod from the old version remains usable. Click here to download the legacy documentation.
Clear notification badge
When a push message arrives via a vendor channel, the device displays a notification badge on the app icon. The push SDK supports automatic badge clearing for Huawei channels only.
-
To automatically clear the badge when the user taps the notification:
// Enable automatic badge clearing on notification tap boolean autoClear = true; MPPush.setBadgeAutoClearEnabled(context, autoClear); // Set the launcher Activity class name — required for badge clearing to work String activityName = "com.mpaas.demo.push.LauncherActivity"; MPPush.setBadgeActivityClassName(context, activityName); -
To manually clear the badge (for example, when the user opens the app directly without tapping a notification), call the following in your
Applicationclass:MPPush.clearBadges(context);
Submit vendor channel token
After the push SDK initializes, it retrieves the vendor channel token and automatically binds and reports it together with the user-created channel token.
To listen for token issuance and reporting events, override the onChannelTokenReceive and onChannelTokenReport methods in MPPushMsgServiceAdapter:
public class MyPushMsgService extends MPPushMsgServiceAdapter {
/**
* Callback of the vendor channel token received.
*
* @param channelToken The vendor channel token.
* @param channel The vendor channel type.
*/
@Override
protected void onChannelTokenReceive(String channelToken, PushOsType channel) {
Log.d("Received vendor channel token: " + channelToken);
Log.d("Vendor: " + channel.getName());
}
/**
* Called when the vendor channel token reporting completes.
*
* @param result The report result.
*/
@Override
protected void onChannelTokenReport(ResultBean result) {
Log.d("Report vendor token " + (result.success ? "Success" : ("Error:" + result.code)));
}
/**
* Controls whether the SDK reports the vendor token automatically.
* Override and return false to report manually.
*/
@Override
protected boolean shouldReportChannelToken() {
return super.shouldReportChannelToken();
}
}
To report the token manually, override shouldReportChannelToken to return false, then call the following after both tokens have been received:
MPPush.report(context, token, channel.value(), channelToken);
Custom notification channels (NotificationChannel)
To set a custom name and description for the default NotificationChannel of the self-built channel, add the following entries to AndroidManifest.xml:
<meta-data
android:name="mpaas.notification.channel.default.name"
android:value="Name" />
<meta-data
android:name="mpaas.notification.channel.default.description"
android:value="Description" />
Adjust push channel priority
Baseline 10.2.3.43 and later let you override the default vendor channel priority order on specific device families. Create a mpaas_push_config.properties file in the assets directory of your project, then add the relevant settings below.
Prefer Honor over HMS on Huawei/Honor devices (optional)
By default, the SDK uses the HMS (Huawei Mobile Services) channel on Huawei and Honor devices. To use the Honor Push channel instead, add:
// Use the Honor channel instead of HMS on Huawei/Honor devices
isHonorBeforeHms=true
Prefer vendor channels over FCM on FCM-capable devices (optional)
On devices that support Firebase Cloud Messaging (FCM), the SDK uses FCM by default. To use the device vendor's native channel instead, add:
// Use the device vendor's channel instead of FCM on FCM-capable devices
isFcmEnd=true