0

I'am trying to find a way to use an NotificationCompat.Builder.addAction(...) to call some code to stop a repeating alarm without starting an activity... but as i understood so far the only thing I can do with this is start intents with Activities. There's any way I can stop the alarm without leaving the notification?

4

2 回答 2

0

您可以通过以 PendingIntent 作为参数调用 set() 函数向警报管理器添加请求。您只需要使用相同的 PendingIntent 调用 cancel() 即可停止它;尽管我非常清楚您的通知问题。

于 2013-02-03T03:53:52.680 回答
0

使用 PendingIntent 在 AlarmManager 上调用 cancel()。

Intent intent = new Intent(this, AlarmReceive.class);
PendingIntent sender = PendingIntent.getBroadcast(this, 0, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);

alarmManager.cancel(sender);

而已

于 2015-09-07T05:55:17.680 回答