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

问题描述 投票:-3回答:1

#####当我点击通知应用程序重新打开时,我想在点击通知后打开一个特定的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());

    }
}
android firebase firebase-realtime-database notifications openurl
1个回答
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);
© www.soinside.com 2019 - 2024. All rights reserved.