【问题标题】:open url in device's browser without direct to App when click firebase's notification单击 Firebase 通知时,在设备浏览器中打开 url 而不直接到应用程序
【发布时间】:2018-05-31 06:54:25
【问题描述】:

当点击 firebase 的通知打开应用程序时。
有没有办法在不打开应用程序的情况下在设备浏览器中打开 url,并在点击通知时直接在浏览器中打开 url?

【问题讨论】:

  • 哥们,你得把URL设置成PendingIntent,这样会直接跳转到浏览器。

标签: android firebase notifications


【解决方案1】:

希望你知道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());
}

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 2016-08-29
    • 1970-01-01
    • 2020-04-08
    • 1970-01-01
    • 2020-05-05
    • 2023-03-19
    • 1970-01-01
    • 2016-03-07
    • 1970-01-01
    相关资源
    最近更新 更多