【发布时间】:2016-06-24 14:47:09
【问题描述】:
我最近更新了我的应用程序以通过 FCM 发送消息,当应用程序在 Jelly Bean 上运行时效果很好。问题是,如果它是 Lollipop 并且应用程序位于 背景 中,则它不会。
我阅读了documentation 并指出当有效负载是数据消息时,它将由onMessageReceived() 处理。我正在发送一个数据负载,不是通知,只要它是 JellyBean,它就会被正确处理。对于 Lollipop,它仅在应用程序位于前台时处理消息。如果没有,什么都不会发生。
这就是我的 FirebaseMessagingService 开头的样子:
public class FirebaseBroadcastReceiverService extends FirebaseMessagingService {
private final String TAG = FirebaseBroadcastReceiverService.class.getName();
@Override
public void onMessageReceived(RemoteMessage message){
Log.i(TAG, "A message is received");
String from = message.getFrom();
Map<String, String> data = message.getData();
.....
}
}
清单:
<application
android:name=".controller.application.AppResources"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher_shadow"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@android:style/Theme.Black.NoTitleBar">
<service
android:name=".model.firebase.FirebaseListenerService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<service android:name=".model.firebase.FirebaseBroadcastReceiverService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
.......
</application>
还有有效载荷:
{
"data": {
"test": "test"
},
"to" : "MY FCM REGISTRATION ID"
}
通过 POST 发送到 https://fcm.googleapis.com/fcm/send,并带有 Authorization 和 Content-type 标头。
我可能已经阅读了与此相关的所有其他 SO 线程,但我找不到答案,而且 Android 监视器中也没有日志跟踪。有人对此有提示吗?
【问题讨论】:
-
你的 fcm 有效载荷是什么样的
-
蒂姆,我把它添加到问题中
标签: android firebase firebase-cloud-messaging