Implement silent push notifications
Introduction
Silent push notifications are a special type of remote notification, mainly used for data synchronization between the App running in the background and the server. For example: when the App is not active and the data within the App is outdated, the server will send a silent push notification, and the App will update the data without any user awareness.
This documentation is applicable to Android smart phones that support Google services.
Prerequisites
Before implementing silent push notifications, please make sure of the following:
- Implement offline push notifications. For more details, please refer to Implement offline push notification.
Implementation steps
-
Contact ZEGOCLOUD Technical Support to configure the
resourceID
for carrying silent push strategies. -
In scenarios where offline push notifications need to be sent (such as call invitation, offline push notification, etc.), fill in the ZIMPushConfig > resourceID with the pre-configured value obtained from ZEGOCLOUD Technical Support. Additionally, fill in the payload field according to the specific business scenario.
pushConfig.resourcesID = @"resourcesID configured by ZEGOCLOUD Technical Support";
-
Create a class that inherits from ZPNsMessageReceiver and declare it as the broadcast receiver for ZPNs. Refer to Implementing Offline Push - Set up the offline push notification feature using the ZPNs SDK for the declaration details.
You can implement the specific logic for receiving silent push notifications in the onThroughMessageReceived method within the new class.
public class MyZPNsReceiver extends ZPNsMessageReceiver {
// push service provider callback on pass-through message
@Override
protected void onThroughMessageReceived(Context context, ZPNsMessage message) {
Log.e("MyZPNsReceiver", "onThroughMessageReceived message:" + message.toString());
// You can get the specific content of the silent push notification through message.getExtras().
}
}
- Once the above steps are completed, you can send silent push notifications to others and receive silent push notifications from others.