2016-09-06 32 views
1

我已经阅读了许多有关Firebase推送通知行为的文档。当我的应用程序处于后台时,我能够在系统托盘上看到通知,但在应用程序处于前台时不会触发onMessageReceived回拨。我可以在我的应用程序中看到该消息收到的日志。我试着用数据有效载荷进行调用,并且没有来自应用服务器的数据载荷我的应用服务器使用php脚本触发fcm apis。以下是我使用Firebase onMessageReceived未在前台应用程序调用

​​

以下是我使用的服务,在我的Android应用

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

<service 
    android:name="service.MyFirebaseInstanceIdService"> 
    <intent-filter> 
     <action android:name="com.google.firebase.INSTANCE_ID_EVENT" /> 
    </intent-filter> 
</service> 
+0

当你说你尝试过使用数据有效载荷时,你的意思是你在PHP代码中用JSON中的'data'替换了'notification'字段?即使你的应用程序处于前台,你的onMessageReceived方法没有被调用? – GeorgeLBA

+0

我怀疑问题出在你的AndroidManifest.xml中。 尝试用“.service.MyFirebaseInstanceIdService”替换“service.MyFirebaseInstanceIdService”(注意开始处的点)。 请参阅https://developer.android.com/guide/topics/manifest/service-element.html中的“android:name”部分 –

+0

@GeorgeLBA我试着一起发送通知和数据有效载荷。在使用和不使用数据有效负载的情况下,当应用处于前台时,不会调用onMessageReceived。我可以在FirebaseMessagingService中看到收到消息的日志 – LvN

回答

3

我有同样的问题PHP脚本。我的问题是<service></service> 标签不在清单文件中的<application></application>标签之外。当我放入<application></application>标签时,问题就解决了。

+0

为我修好了。谢谢@Jamal –

+0

我真的为此疯狂起来,多次检查应用程序,切换到不同的模拟器。但是,谢谢你救了我的一天。 – Hayra

相关问题