Cloud Messaging
Cloud Messaging is used for sending notification to user for things like warning or Marketing Campaign.
Devbase support both Firebase Cloud Messaging and Huawei Push Kit.
Service¶
For interacting with the notification being sent, you're required to implement service to your Android Project.
Implement two services both for FCM and HSP to your Android Project. Follow this:
DevMessaging
¶
Devbase provide DevMessaging
for operation relating cloud messaging for your Android Project. Initialize it like this:
val messaging by lazy { MobileService.messaging }
Get Token¶
Get your current token that registered devicce by calling method getToken()
like this:
messaging.getToken("putYourAGCPProjectIdHere") { token ->
// put action that required your token here
}
Delete Token¶
For releasing current registered token (example: for logging out user), call deleteToken()
like this:
messaging.deleteToken("putYourAGCPProjectIdHere") {
// put action that invoked when token is deleted
}
Info
By default, deleting token resulted a new token will be generated for your device. You can observe the new token in your Service.
Subscribe to Topic¶
Set device to observe notification that being sent to certain topic by calling subscribeToTopic()
method:
messaging.subscribeToTopic("yourTopicName")
Unsubscribe to Topic¶
Unregister your device from observing topic by calling unsubscribeFromTopic()
method:
messaging.unsubscribeFromTopic("yourTopicName")