Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android notifications: onMessageReceived not called

First of all, it's not because the app is in the background.

The notifications are sent with a data message payload. In the Play console it says the messages are 'Acknowledged', so they're reaching the device. For most users, the onMessageReceived method is called, but for a minority, it isn't. Why would this be?

AndroidManifest:

<service android:name=".push.MyFirebaseInstanceIDService">
    <intent-filter>
        <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
    </intent-filter>
</service>
<service android:name=".push.MyFirebaseMessagingService">
    <intent-filter>
         <action android:name="com.google.firebase.MESSAGING_EVENT"/>
    </intent-filter>
</service>

MyFirebaseMessagingService:

public class MyFirebaseMessagingService extends FirebaseMessagingService {

...
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
...
}
like image 278
Questioner Avatar asked Jan 03 '23 05:01

Questioner


1 Answers

One of the main reasons why this could be happening is because the particular user has changed his login details or is using a different account when using the app. In this particular case, the particular device token would be receiving the notification, but since he is using a a different account, the notification is not displayed. One way to go around this issue is to clear the user's device token each time the user logs out and saved the newly created one, when a user logs in again. This way the device token is kept updated and the user will receive the notifications.

like image 145
Michele La Ferla Avatar answered Jan 15 '23 04:01

Michele La Ferla