相关疑难解决方法(0)

当应用程序在后台时,不会调用Firebase onMessageReceived

我正在使用Firebase,并在应用程序处于后台时测试从我的服务器向我的应用发送通知.通知成功发送,甚至出现在设备的通知中心,但是当通知出现或甚至我点击它时,我的FCMessagingService内的onMessageReceived方法永远不会被调用.

当我在我的应用程序位于前台时对此进行测试时,调用了onMessageReceived方法,一切正常.当应用程序在后台运行时会出现此问题.

这是预期的行为,还是有办法解决这个问题?

这是我的FBMessagingService:

import android.util.Log;

import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;

public class FBMessagingService extends FirebaseMessagingService {

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Log.i("PVL", "MESSAGE RECEIVED!!");
        if (remoteMessage.getNotification().getBody() != null) {
            Log.i("PVL", "RECEIVED MESSAGE: " + remoteMessage.getNotification().getBody());
        } else {
            Log.i("PVL", "RECEIVED MESSAGE: " + remoteMessage.getData().get("message"));
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

android firebase firebase-cloud-messaging

201
推荐指数
15
解决办法
16万
查看次数

FirebaseMessagingService 11.6.0 HandleIntent

FirebaseMessagingService有方法onMessageReceived(),我们应该哪个override来处理notifications,但是这只能在应用程序中Foreground.

要处理notifications应用程序在后台时,我曾经覆盖handleIntent,只是调用onMessageReceived().

FirebaseMessagingService11.6.0中,该方法handleIntent成为最终的,据说,我无法像我一样覆盖它.

当我的应用程序在11.6.0中处于后台时,我该如何处理通知?

public class NotificationsListenerService extends FirebaseMessagingService {
    private static final String TAG = "NotificationsListenerService";

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) 

        String notifyData = remoteMessage.getData().get("notifData");

        if(notifyData.contains("|")){
            String[] itens = notifyData.split("\\|");
            notifyData = itens[0];
        }


        String notifyType = remoteMessage.getData().get("notifType");
        String title = remoteMessage.getData().get("title");
        String message = remoteMessage.getData().get("body");

        if(!isAppInForeground(App.getContext())){
            sendNotification(title, message, notifyData, notifyType);
        }
    }

    @Override
    public final void handleIntent(Intent intent) …
Run Code Online (Sandbox Code Playgroud)

android android-intent firebase firebase-cloud-messaging

5
推荐指数
1
解决办法
1万
查看次数