我想将带有FCM的网址发送到android应用程序。单击FCM通知时是否可以打开浏览器,而不是打开启动器活动?我知道可以重写onMessageReceived()
方法,但我不想这样做。我检查了有效负载中的click_action
参数,但正如Firebase所说:
如果指定,将启动具有匹配意图过滤器的活动 当用户点击通知时。
我尝试像这样在Firebase cloudMessaging面板中的CustomData中添加click_action
:
但是它不起作用,而是打开应用程序。
为此,我使用邮递员发送通知,并将click_action
添加到notification
对象中,如下所示:
通知已发送到我的设备,但单击该按钮后,没有任何反应!
重要提示:我的apk在GooglePlay上发布,我无法更改应用程序的源代码。
请任何人帮助。
答案 0 :(得分:0)
当您的应用程序在后台运行时。通知将发送到设备的系统托盘。用户点击通知会默认打开应用启动器。
如果消息中包含数据,则通知将发送到设备的系统托盘,而数据有效载荷将在启动器活动的意图范围内传递。
因此您可以根据不同的数据来处理条件。
{
...
"notification": {
"click_action": "activity action"
},
....
}
2。在最主要的方面,您必须配置过滤器。
<intent-filter>
<action android:name="some action" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
然后单击它,它将打开该动作活动。 这是文件描述:
如果指定,当用户单击通知时,将启动具有匹配的意图过滤器的活动。
所以我认为您尝试将click_action acton设置为与浏览器选择器操作或“ Intent.ACTION_VIEW”以及类似“ http://”的数据集相匹配
我希望可以为您提供帮助
答案 1 :(得分:0)
在PendingIntent中传递setData的意图。
Intent notificationIntent = new Intent(Intent.ACTION_VIEW);
notificationIntent.setData(Uri.parse(link));
PendingIntent pending = PendingIntent.getActivity(this, 0, notificationIntent,
Intent.FLAG_ACTIVITY_NEW_TASK);
myNotification.setContentIntent(pending);