相关疑难解决方法(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万
查看次数