Android的通知删除

编程入门 行业动态 更新时间:2024-10-14 22:17:15
本文介绍了Android的通知删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我开发一个应用程序,用户可以为非常事件创建事件和设置通知。我现在用的是下面的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的通知删除

本文发布于:2023-11-27 19:51:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639374.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:通知   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!