应用程序打开时后台 firebase 显示对话框的通知
notification on background firebase show dialog when apps open
对不起我的标题,但让我解释一下。
我在我的应用程序上使用 firebase 云消息传递。现在,我需要 运行 应用程序然后显示包含通知 body 和标题的对话框,当 应用程序不在 运行ning 或在后台 时,在我之后触摸通知。
对于默认的 FCM,当应用程序不是 running/in 后台时,我触摸通知然后应用程序 running/go 到前台。
谁能指导我处理吗?
Handle notification messages in a backgrounded app
When your app is in the background, Android directs notification messages to the system tray. A user tap on the notification opens the app launcher by default.
This includes messages that contain both notification and data payload (and all messages sent from the Notifications console). In these cases, the notification is delivered to the device's system tray, and the data payload is delivered in the extras of the intent of your launcher Activity.
When you send a notification message with a data payload (notification and data) and the app is in the background you can retrieve the data from the extras of the intent that is launched as a result of the user tapping on the notification.
来自点击通知时启动 MainActivity 的 FCM sample:
if (getIntent().getExtras() != null) {
for (String key : getIntent().getExtras().keySet()) {
String value = getIntent().getExtras().getString(key);
Log.d(TAG, "Key: " + key + " Value: " + value);
}
}
编辑:
在 onMessageRecieved(RemoteMessage remoteMessage)
方法中使用 remoteMessage.getData()
获取服务器发送的数据 returns a Map<String,String>
.
现在创建一个 Intent 并指定一个 class 以在单击通知时启动,并在此 Intent 中放置您的通知数据。喜欢:
Intent resultIntent = new Intent(getApplicationContext(), MainActivity.class);
resultIntent.putExtra("notification_data", data.getData());
现在,当您显示通知时,将此 Intent 传递给 pendingIntent。
当 MainActivity.class 通过点击通知启动时,只需像这样获取数据:
Map<String,String> notificationDataMap
= getIntent().getSerializableExtra("notification_data");
所以从地图你可以得到数据。
对不起我的标题,但让我解释一下。 我在我的应用程序上使用 firebase 云消息传递。现在,我需要 运行 应用程序然后显示包含通知 body 和标题的对话框,当 应用程序不在 运行ning 或在后台 时,在我之后触摸通知。
对于默认的 FCM,当应用程序不是 running/in 后台时,我触摸通知然后应用程序 running/go 到前台。
谁能指导我处理吗?
Handle notification messages in a backgrounded app
When your app is in the background, Android directs notification messages to the system tray. A user tap on the notification opens the app launcher by default.
This includes messages that contain both notification and data payload (and all messages sent from the Notifications console). In these cases, the notification is delivered to the device's system tray, and the data payload is delivered in the extras of the intent of your launcher Activity.
When you send a notification message with a data payload (notification and data) and the app is in the background you can retrieve the data from the extras of the intent that is launched as a result of the user tapping on the notification.
来自点击通知时启动 MainActivity 的 FCM sample:
if (getIntent().getExtras() != null) {
for (String key : getIntent().getExtras().keySet()) {
String value = getIntent().getExtras().getString(key);
Log.d(TAG, "Key: " + key + " Value: " + value);
}
}
编辑:
在 onMessageRecieved(RemoteMessage remoteMessage)
方法中使用 remoteMessage.getData()
获取服务器发送的数据 returns a Map<String,String>
.
现在创建一个 Intent 并指定一个 class 以在单击通知时启动,并在此 Intent 中放置您的通知数据。喜欢:
Intent resultIntent = new Intent(getApplicationContext(), MainActivity.class);
resultIntent.putExtra("notification_data", data.getData());
现在,当您显示通知时,将此 Intent 传递给 pendingIntent。
当 MainActivity.class 通过点击通知启动时,只需像这样获取数据:
Map<String,String> notificationDataMap
= getIntent().getSerializableExtra("notification_data");
所以从地图你可以得到数据。