这是我的代码,我想在用户点击通知时打开一个 URL。
这是代码:
Intent notificationIntent = new Intent(Intent.ACTION_VIEW);
notificationIntent.setData(Uri.parse(link));
Notification myNotification = new NotificationCompat.Builder(ctx)
.setSmallIcon(R.drawable.ic_launcher)
.setAutoCancel(false)
.setLargeIcon(remote_picture)
.setContentTitle(onvan)
.setContentIntent(notificationIntent)
.setContentText(msg)
.setStyle(notiStyle)
.build();
notificationManager.notify(1, myNotification);
我收到这个错误:
NotificationCompat.Builder
类型中的方法 setContentIntent(PendingIntent)
不适用于参数 (Intent)
我做错了什么?当用户点击通知时,我如何告诉它打开浏览器?
最佳答案
您必须向通知添加待定 Intent 。
Intent notificationIntent = new Intent(Intent.ACTION_VIEW);
notificationIntent.setData(Uri.parse(link));
PendingIntent pending = PendingIntent.getActivity(this, 0, notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
myNotification.setContentIntent(pending);
关于android - 如何在 Android 中点击通知时打开浏览器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31889415/