![](/img/trans.png)
[英]Where is FCM Intent with data delivered, when app is in background?
[英]Extra Intent data getting null when application in background for FCM
細節:
觀察結果:
雖然通知確實出現在系統托盤中,但數據在意圖中不可用。 在onNewIntent
或onCreate
中,附加值是 null。
預期成績:
根據 Firebase Cloud Messaging 文檔,當應用程序 State 在后台並發送帶有數據的通知時,通知會出現在系統托盤中,並且數據將在意圖的額外內容中可用。
@Override
public void onCreate() {
Bundle extras = getintent().getExtras();
---> extras is always null when app is not running or when app is in background
}
或者
@Override
public void onNewIntent(Intent intent) {
Bundle extras = intent.getExtras();
---> extras is always null when app is not running or when app is in background
}
備注:App State在Foreground時數據可用。 但是通知控制台幾乎無法使用這個錯誤,因為所有(后台,應用程序未運行,前台)用戶都需要能夠在通知中獲取數據。 否則,開發人員如何知道用戶看到或沒有看到哪些數據(例如,是否向用戶顯示了 10% 的折扣)。
您必須通過在 AndroidManifest.xml 中添加以下行來為啟動器活動設置默認類別標簽:
<category android:name="android.intent.category.DEFAULT" />
像這樣:
<activity android:name=".ui.splash.SplashActivity" android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.