Уведомление Android Удалить - PullRequest
2 голосов
/ 08 марта 2011

У меня есть приложение, в котором пользователь может создавать события и устанавливать уведомления для этого самого события.Я использую следующий код:

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);

Но это не работает вообще.Как это сделать?

1 Ответ

0 голосов
/ 13 марта 2011

см

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);

Само собой разумеется, что я использовал тот же тег при настройке уведомления!?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...