Android notifications: onMessageReceived is not called

First of all, this is not because the application is in the background.

Notifications are sent with a payload of data. The Play console says that the messages are "Confirmed", so they get to the device. For most users, the method onMessageReceivedis invoked, but for a minority, it is not. Why should it 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) {
...
}
+4
source share
7 answers

, , , . , , . - , , . , .

+3

, onMessageReceived , . , , , .

click_action, , , . , click_action.

,

getIntent().getExtras();

, , .

handleIntent(Intent intent) FirebaseMessagingService.

handleIntent() , , .

. docs.

+2

firebase. :

public class TixDoFirebaseIntentService extends FirebaseInstanceIdService {
    @Override
    public void onTokenRefresh() {
        Common.log("FirebaseToken :"+FirebaseInstanceId.getInstance().getToken());
    }
}

, , , .

+1

?

    <service android:name="push_notification.service.FirebaseIDService">
              <intent-filter>
                    <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
              </intent-filter>
    </service>

, , FirebaseIDService, FirebaseInstanceIdService . , - , , https://www.survivingwithandroid.com/2016/09/android-firebase-push-notification.html, firebase .

- , .

: - , . onNewToken (String token) FirebaseMessageService .

+1

:

1.Upgrade your firebase to version compile com.google.firebase:firebase-messaging:10.2.1
2.Override handleIntent(Intent intent) method in your FirebaseMessagingService class.

handleIntent() , , .

+1

, ,

fcm "Single Device".

.

+1

" state:

, service, extends FirebaseMessagingService.

onMessageReceived onDeletedMessages.

10 . Android , .

, Firebase.

onMessageReceived Job RemoteMessage - , 10 ( ). docs Override onMessageReceived, , .

always sending a task, as a rule, dispenses with the possibility of terminating the associated process no matter how long it takes to return. onMessageReceivedProbably Called, but terminated.

+1
source

Source: https://habr.com/ru/post/1688878/


All Articles