When An App Is In Background, Onmessagereceived Method Is Not Firing
Actually i need to show badge in app icon but i don't know how to get badge and why onMessageReceived not call when app is in background or app is not running. public class Custom_
Solution 1:
There are two types of FCM
notification
Messages: Sending a payload with this message type triggers onMessageReceived()
only when your app is in foreground.
data
Messages: Sending a payload with only this specific message type triggers onMessageReceived()
regardless if your app is in foreground/background.
Reference: https://firebase.google.com/docs/cloud-messaging/android/receive#handling_messages
Solution 2:
Add service to AndroidManifest.xml
. Also make sure token is not expired.
<serviceandroid:name=".FirebaseMessagingService"><intent-filter><actionandroid:name="com.google.firebase.MESSAGING_EVENT"/></intent-filter></service>
Refresh Token if it is expired.
@OverridepublicvoidonTokenRefresh() {
// Get updated InstanceID token.String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
// If you want to send messages to this application instance or// manage this apps subscriptions on the server side, send the// Instance ID token to your app server.sendRegistrationToServer(refreshedToken);
}
Post a Comment for "When An App Is In Background, Onmessagereceived Method Is Not Firing"