我有一个包含 2 个操作的通知。一个意图打开一个活动,另一个打开浏览器网络。
我的代码:
Intent intent1 = new Intent(context, NotificationClickActivity.class);
PendingIntent pIntent1 = PendingIntent.getActivity(context, 0, intent1, PendingIntent.FLAG_CANCEL_CURRENT);
String url = "http://www.google.com";
Intent browserIntent = new Intent(Intent.ACTION_VIEW);
browserIntent.setData(Uri.parse(url));
PendingIntent pBrowserIntent = PendingIntent.getActivity(context, 1, browserIntent, PendingIntent.FLAG_CANCEL_CURRENT);
// Build notification
Notification noti = new Notification.Builder(context)
.setContentTitle(title)
.setContentText(shortDescription)
.setStyle(new Notification.BigTextStyle().bigText(longDescription))
.setSmallIcon(R.drawable.small_defaulticon)
.setAutoCancel(true)
.setContentIntent(pIntent1)
.addAction(R.drawable.playstore_icon_32, "Dettagli", pIntent1)
.setContentIntent(pBrowserIntent)
.addAction(R.drawable.small_defaulticon, "Vai al sito", pBrowserIntent).build();
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
// Hide the notification after its selected
noti.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, noti);
如果我点击通知,它就会消失,但如果我点击 2 个操作之一,它会打开正确的意图,但不会清除通知。我也尝试过.setDeleteIntent(myPendingIntent)
,但什么也没有……我想知道我哪里出错了……
我的通知屏幕...
谢谢!