バックグラウンドデータを画面に渡すことができません。バックグラウンドでは、アプリケーションは画面を正しく呼び出していますが、この画面に必要なデータは通知内の「データ」(データオブジェクトのID)に収められていません。 前景で私は正しく "データ"を得ました。バックグラウンドでAndroid:バックグラウンドデータを通過するFCMプッシュ通知
通知JSON
{
"to" : "akshih890uhnkjh389jfkn3...",
"priority" : "normal",
"time_to_live" : 0,
"data" : {
"type" : "my_type",
"id" : "my_id"
},
"notification" : {
"body" : "Test body",
"title" : "Test title",
"click_action" : ".MyActivity"
}
}
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
String title = remoteMessage.getNotification().getTitle();
String body = remoteMessage.getNotification().getBody();
String clickAction = remoteMessage.getNotification().getClickAction();
Map<String, String> data = remoteMessage.getData();
Gson gson = new Gson();
MyObject myObject = new MyObject(data.get("id"), data.get("type"), remoteMessage.getNotification().getTitle(),
remoteMessage.getNotification().getBody());
Intent intent = new Intent(myObject.getClickAction());
intent.putExtra("id", myObject.getId());
PendingIntent contentIntent = PendingIntent.getActivity(
this, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
sendFCMNotification(title, body, contentIntent);
}
MyActivity
if(getIntent() != null) {
Bundle extras = getIntent().getExtras();
code = extras.getString("id");
}
こんにちは..私はあなたも通知にadditiotionで渡さなければならないと考えています(通知は、背景のforforegroundメッセージです) –
[アプリがバックグラウンドであるかどうかにかかわらずプッシュ通知が正しく動作しません](https: /stackoverflow.com/questions/37876257/push-notification-works-incorrectly-when-app-is-on-background-or-not-running) –