我在我的應用程序中實施FCM(Firebase消息傳遞服務)。這裏一切似乎都很好,除非應用程序處於後臺狀態時,我無法提取預期的通知數據。當應用程序處於後臺狀態時,Google FCM getIntent不返回預期數據
基於概念:有在FCM兩種類型的消息:
顯示的消息:這些消息只有當你的應用程序在前臺工作。
數據的消息:論文信息工作,即使你的應用程序在後臺 當我們的應用程序是在後臺,Android的指示通知消息到系統托盤。
處理數據的消息您的通知應該有click_action = 「YOUR_ACTION」場。
我的消息將是這樣的:
{
"data": {
"body": "here is body",
"title": "Title",
"click_action": "YOUR_ACTION"
},
"to": "ffEseX6vwcM:APA91bF8m7wOF MY FCM ID 07j1aPUb"
}
活動將顯示該清單文件會喜歡這樣的消息:
<activity
android:name=".NotificationActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Dialog"
android:windowSoftInputMode="stateHidden" >
<intent-filter>
<action android:name="YOUR_ACTION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
點擊通知後,它會重定向到我NotificationActivity
。在我NotificationActivity
在onCreate
和onNewIntent
方法,我用這種方式提取消息:
Bundle bundle=getIntent().getExtras();
if(bundle!=null) {
for (String key : bundle.keySet()) {
Object value = bundle.get(key);
Log.d("DATA_SENT", String.format("%s %s (%s)", key,
value.toString(), value.getClass().getName()));
}
}
在
不幸的是我的NotificationActivity
我得到下面的消息是:
google.sent_time:1471631793774
從:50711789666
google.message_id 0:1471631793776823%098e508d098e508d
collapse_key的:com.myapp.package_name
但哪裏是我的預期通知數據?
這裏是我的系統配置:
的Android Studio版本:2.1.3
火力地堡版本:com.google.firebase:火力-AUTH:9.0.1
Google Play服務版本:com.google.android.gms:play-services:9.2。1
下面是一些相關鏈接:
- https://github.com/firebase/quickstart-android/issues/4
- https://github.com/firebase/quickstart-android/issues/47
- How to handle notification when app in background in Firebase
- Firebase onMessageReceived not called when app in background
- How to handle notification when app in background in Firebase
在此先感謝。對不起,英文不好。
請問您可以發佈您的onMessageReceived方法嗎?我認爲問題可能在於此方法,因此NotificationActivity未收到通知數據。 – GeorgeLBA