MessagingReceiver
Receive UnifiedPush messages (new endpoints, unregistrations, push messages, errors) from the distributors
Expose a receiver
You need to expose a receiver that extend MessagingReceiver and override the following methods:
class CustomReceiver: MessagingReceiver() {
override fun onMessage(context: Context, message: PushMessage, instance: String) {
// TODO: handle message, eg. to sync remote data or show a notification to the user
}
override fun onNewEndpoint(context: Context, endpoint: PushEndpoint, instance: String) {
// TODO: send new endpoint to the app server
}
override fun onRegistrationFailed(context: Context, reason: FailedReason, instance: String) {
// TODO: retry depending on the reason
}
override fun onUnregistered(context: Context, instance: String){
// TODO: ask to register to another distributor
}
}class CustomReceiver extends MessagingReceiver {
public CustomReceiver() {
super();
}
@Override
public void onMessage(@NotNull Context context, @NotNull PushMessage message, @NotNull String instance) {
// TODO: handle message, eg. to sync remote data or show a notification to the user
}
@Override
public void onNewEndpoint(@NotNull Context context, @NotNull PushEndpoint endpoint, @NotNull String instance) {
// TODO: send new endpoint to the app server
}
@Override
public void onRegistrationFailed(@NotNull Context context, @NotNull FailedReason reason, @NotNull String instance) {
// TODO: retry depending on the reason
}
@Override
public void onUnregistered(@NotNull Context context, @NotNull String instance) {
// TODO: ask to register to another distributor
}
}Edit your manifest
The receiver has to be exposed in the AndroidManifest.xml in order to receive the UnifiedPush messages.
<receiver android:exported="true" android:enabled="true" android:name=".CustomReceiver">
<intent-filter>
<action android:name="org.unifiedpush.android.connector.MESSAGE"/>
<action android:name="org.unifiedpush.android.connector.UNREGISTERED"/>
<action android:name="org.unifiedpush.android.connector.NEW_ENDPOINT"/>
<action android:name="org.unifiedpush.android.connector.REGISTRATION_FAILED"/>
</intent-filter>
</receiver>Functions
Define the KeyManager to use. DefaultKeyManager by default.
A new message is received. The message contains the decrypted content of the push message for the instance
A new endpoint is to be used for sending push messages. The new endpoint should be send to the application server, and the app should sync for missing notifications.
The registration is not possible, eg. no network, depending on the reason, you can try to register again directly.
This application is unregistered by the distributor from receiving push messages