我开发了一个应用程序,用户可以在其中创建事件并为该事件设置通知。我使用以下代码。
final Notification notifyDetails = new Notification(R.drawable.icon, "Myapp",calendar.getTimeInMillis());
Context context = getApplicationContext();
Intent notifyIntent = new Intent(context, ViewDoughnut.class);
PendingIntent pendingIntent = PendingIntent.getActivity(ViewCal.this, 0, notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
notifyDetails.setLatestEventInfo(context, contentTitle, contentText, pendingIntent);
notifyDetails.flags = Notification.FLAG_ONGOING_EVENT;
mNotificationManager.notify(eventId, notifyDetails);
如果用户删除与其对应的事件,我想删除任何特定通知。我试过以下代码。
mNotificationManager.cancel(eventId);
但它根本不起作用。怎么做?
答案 0 :(得分:0)
见
http://developer.android.com/guide/topics/ui/notifiers/notifications.html#ManageYourNotifications
和
http://developer.android.com/reference/android/app/NotificationManager.html#cancel%28int%29
我用标签取消了我的通知:
int IdFromNotification = intent.getIntExtra("myId", -1);
NotificationManager nManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nManager.cancel(IdFromNotification + "", IdFromNotification);
不用说我在设置通知时使用了相同的标签!?