我开发一个应用程序,用户可以为非常事件创建事件和设置通知。我现在用的是下面的code。
I have developing an App where the user can create event and set notification for that very event. I am using the following code.
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);
我想删除任何具体通知,如果用户删除与之相对应的事件。我曾尝试与下面code。
I want to delete any specific notification if the user delete the event corresponding to it. I have tried with following code.
mNotificationManager.cancel(eventId);
但它是不工作的。怎么办呢?
But it is not working at all. How to do it?
推荐答案看
developer.android/guide/topics/ui/notifiers/notifications.html#ManageYourNotifications
和
的developer.android/reference/android/app/NotificationManager.html#cancel%28int%29
我使用的标签取消我的通知:
i used the tag to cancel my notifications:
int IdFromNotification = intent.getIntExtra("myId", -1); NotificationManager nManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nManager.cancel(IdFromNotification + "", IdFromNotification);
不用说,我设置的通知时使用的相同的标签!?
needless to say that i used the same tag when setting the notification!?
更多推荐
Android的通知删除
发布评论