点击firebase的通知,在设备的浏览器中打开网址,而无需直接发送到应用

时间:2018-05-31 06:54:26

标签: android firebase notifications

点击firebase的通知打开应用。
设备浏览器中有没有打开网址的方式没有打开应用程序,并在点击通知时直接在浏览器中打开网址?

1 个答案:

答案 0 :(得分:0)

希望您知道how to get message body from notification只需在您打开通知点击活动的地方尝试此操作,请使用此

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));

onMessageReceived(RemoteMessage remoteMessage)中调用此方法并从通知中获取您的网址,并在方法参数中传递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());
}

希望它有所帮助。