如何在外部浏览器中打开 url 点击 android 推送通知?

Gop*_*ena 6 java push-notification android-notifications firebase-cloud-messaging

当用户点击推送通知时,我试图用一个 url 打开浏览器,我在 stackoverflow 中搜索,我找到了这个

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        startActivity(browserIntent);
Run Code Online (Sandbox Code Playgroud)

但这对我不起作用。
我正在寻找过去 5 天的解决方案,但未能找到。
这是我的代码

public class MyFirebaseMessagingService extends FirebaseMessagingService {


@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

// Intent notificationIntent = new Intent(this, HomeActivity.class);

Intent notificationIntent = new Intent(Intent.ACTION_VIEW);
notificationIntent.setData(Uri.parse("https://play.google.com/store/apps/details?id=com.example.android"));
startActivity(notificationIntent);


notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
final PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent,
PendingIntent.FLAG_ONE_SHOT);

int notificationId = new Random().nextInt(60000);
Bitmap bitmap = getBitmapfromUrl(remoteMessage.getData().get("image-url"));

Intent likeIntent = new Intent(Intent.ACTION_VIEW);
likeIntent.putExtra(NOTIFICATION_ID_EXTRA,notificationId);
likeIntent.putExtra(IMAGE_URL_EXTRA,remoteMessage.getData().get("image-url"));
PendingIntent likePendingIntent = PendingIntent.getService(this,
notificationId+1,likeIntent, PendingIntent.FLAG_ONE_SHOT);


Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);


if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
setupChannels();
}

NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, ADMIN_CHANNEL_ID)
.setLargeIcon(bitmap)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(remoteMessage.getData().get("title"))
.setStyle(new NotificationCompat.BigPictureStyle()
.setSummaryText(remoteMessage.getData().get("message"))
.bigPicture(bitmap))/*Notification with Image*/
.setContentText(remoteMessage.getData().get("message"))
.setAutoCancel(true)
.setSound(defaultSoundUri)
.addAction(R.drawable.ic_favorite_true,
getString(R.string.notification_add_to_cart_button),likePendingIntent)
.setContentIntent(pendingIntent);

notificationManager.notify(notificationId, notificationBuilder.build());

}
Run Code Online (Sandbox Code Playgroud)

寻找任何帮助..

小智 0

我在tutorialpoint.com 中搜索并显示了一个按钮,也许可以提供帮助。

Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
Run Code Online (Sandbox Code Playgroud)