单击firebase的通知时,在设备的浏览器中打开URL而不直接到App
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了单击firebase的通知时,在设备的浏览器中打开URL而不直接到App相关的知识,希望对你有一定的参考价值。
当点击firebase的通知打开应用程序时。 在没有打开应用程序的设备浏览器中有没有办法打开网址,并在点击通知时直接在浏览器中打开网址?
答案
希望你知道how to get message body from notification只需尝试这个你打开活动的通知点击,使用它
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
要么
在你的onMessageReceived(RemoteMessage remoteMessage)
中调用这个方法并从通知中获取你的url并在方法参数中传递url
。
private void sendNotification(String url) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,browserIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notification =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification)
.setContentTitle(getString(R.string.app_name))
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(body)
.setBigContentTitle(title))
.setContentText(body)
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.setDefaults(NotificationCompat.DEFAULT_SOUND);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0,notification.build());
}
希望能帮助到你。
以上是关于单击firebase的通知时,在设备的浏览器中打开URL而不直接到App的主要内容,如果未能解决你的问题,请参考以下文章
在应用关闭时单击 Firebase 通知后打开特定的活动/片段
Android - 点击时 Firebase 通知会打开一个 Activity