简体   繁体   English

FCM-单击系统任务栏通知时如何遍历特定活动

[英]FCM - How to traverse to a particular activity when system tray notification is clicked

We are using FCM to show push notification to the end user . 我们正在使用FCM向终端用户显示推送通知。 FCM successfully raised the notification and the user is seeing the notification from the system tray.I am using FCM console Notification composer for testing. FCM成功发出了通知,并且用户正在系统托盘中看到该通知。我正在使用FCM控制台Notification Composer进行测试。

I will keep my app in the background and send message from FCM console. 我将我的应用程序保留在后台,并从FCM控制台发送消息。

The requirement is to navigate to specific activity in the application when the tray message is clicked by the user(when the application in background). 要求是当用户单击任务栏消息时(在后台应用程序时)导航到应用程序中的特定活动。 Right now , by default it opens the app launcher page. 现在,默认情况下,它会打开应用启动器页面。

I couldn't get proper answer from google . 我无法从google得到正确的答案。 Most of the answers are for GCM and most are not working solution . 大多数答案是针对GCM的,大多数不是可行的解决方案。 I don't find proper document in FCM page. 我在FCM页面中找不到正确的文档。

Handle notification messages in a backgrounded app 在后台应用程序中处理通知消息

When your app is in the background, Android directs notification messages to the system tray. 当您的应用程序在后台运行时,Android会将通知消息定向到系统任务栏。 A user tap on the notification opens the app launcher by default. 默认情况下,用户点击通知会打开应用启动器。

FCM page - 

This includes messages that contain both notification and data payload (and all messages sent from the Notifications console). 这包括同时包含通知和数据有效负载的消息(以及从Notifications控制台发送的所有消息)。 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. 在这些情况下,通知将传递到设备的系统托盘,而数据有效载荷将在启动器活动的意图之外传递。

Thanks 谢谢

You have to add <intent-filter> with action inside AndroidManifest.xml and set click_action in the notification payload then it will work when either app is in background or killed. 您必须在AndroidManifest.xml内添加带有操作的<intent-filter>并在通知有效负载中设置click_action ,然后它才能在应用程序处于后台或被click_action时起作用。

You can refer below link: 您可以参考以下链接:

open a specific activity from firebase notification 从Firebase通知中打开特定活动

put this code inside onMessageReceived() method 将此代码放在onMessageReceived()方法中

 private void sendNotification(String messageBody) {
            Intent intent = new Intent(this, YOUR_TARGET_ACTIVITY.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
                    PendingIntent.FLAG_ONE_SHOT);

            Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.ic_stat_ic_notification)
                    .setContentTitle("FCM Message")
                    .setContentText(messageBody)
                    .setAutoCancel(true)
                    .setSound(defaultSoundUri)
                    .setContentIntent(pendingIntent);

            NotificationManager notificationManager =
                    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

            notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
        }

You need to handle the push yourself, and don't allow Google to automatically add the status notification. 您需要自己处理推送,并且不允许Google自动添加状态通知。 By default, the Firebase Console will take over delivery of the status notification for you, and not allow much else to happen. 默认情况下,Firebase控制台将为您接管状态通知的交付,并且不会发生其他事情。 In your Firebase receiver, simply build your own notification based on the data pattern (that you set up) in the push, and add a PendingIntent to the notification. 在Firebase接收器中,只需根据推送中的数据模式(您设置的) 构建自己的通知 ,然后将PendingIntent添加到通知中即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 FCM 中单击通知时打开特定活动 - Open specific Activity when notification clicked in FCM 单击通知时如何打开活动中的特定片段 - how to open particular fragment which in an activity when notification is clicked 单击 fcm 通知而不是打开启动器活动时打开浏览器 - Open browser when clicked on fcm notification instead of opening launcher activity 如何通过单击系统托盘Firebase上的通知来了解启动器活动是否已启动 - How to know if the launcher activity is started by clicking on notification on system tray Firebase 从系统托盘android firebase FCM中的通知中检索通知值 - Retrieve notification values from a notification in system tray android firebase FCM 设备系统托盘中带有有效负载的FCM通知未传递给App - FCM Notification with payload in device's system tray not getting passed to App 当它涉及系统托盘时,如何禁用显示通知? - How to disable showing notification when it it comes to the system tray? 单击通知时如何打开特定片段 - how to open particular fragment when notification is clicked 如何在单击通知时启动活动? - How to launch an activity when notification is clicked? 单击该活动如何打开启动通知的活动? - How to open the activity that launched a notification when clicked on it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM