在后台运行应用程序时未调用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")); } } }