如何通过单击Android中的通知来打开URL

时间:2019-04-18 08:04:43

标签: android firebase firebase-realtime-database notifications openurl

#####当我单击通知时,应用会重新打开,我想在单击通知后打开特定的URL。 #####

![https://drive.google.com/open?id=1YIoLK3039IbtswnSdc5k7TKbp6UPhWKf] [在此处查看图片] 1

public class MyFirebaseMessagingService extends FirebaseMessagingService {
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Intent iA = new Intent(this, MainActivity.class);
        iA.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this,0,iA,PendingIntent.FLAG_ONE_SHOT);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
        notificationBuilder.setContentTitle("FCM NOTIFICATION");
        notificationBuilder.setContentText(remoteMessage.getNotification().getBody());
        notificationBuilder.setAutoCancel(true);
        notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
        notificationBuilder.setContentIntent(pendingIntent);
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(0,notificationBuilder.build());

    }
}

1 个答案:

答案 0 :(得分:1)

您可以在通知中使用这样的待定意图:

Intent notificationIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_ONE_SHOT);