Android:使用AlarmManager设置所有待处理内容(Android: Get all PendingIntents set with AlarmManager)
我正在设置这样的闹钟:
alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTime, pendingEvent);我有兴趣删除以前设置的所有报警,清除它们。
有没有办法做到这一点,或者获取当前设置的所有闹钟,以便我可以手动删除它们?
I'm setting an alarm like this:
alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTime, pendingEvent);I'm interested in removing all the alarms that where previously set, clearing them.
Is there a way for me to do that or to get all the alarms that are currently set so that I can delete them manually ?
最满意答案
您需要创建您的待处理意图,然后取消它
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent updateServiceIntent = new Intent(context, MyPendingIntentService.class); PendingIntent pendingUpdateIntent = PendingIntent.getService(context, 0, updateServiceIntent, 0); // Cancel alarms try { alarmManager.cancel(pendingUpdateIntent); } catch (Exception e) { Log.e(TAG, "AlarmManager update was not canceled. " + e.toString()); }You need to create your pending intent and then cancel it
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent updateServiceIntent = new Intent(context, MyPendingIntentService.class); PendingIntent pendingUpdateIntent = PendingIntent.getService(context, 0, updateServiceIntent, 0); // Cancel alarms try { alarmManager.cancel(pendingUpdateIntent); } catch (Exception e) { Log.e(TAG, "AlarmManager update was not canceled. " + e.toString()); }更多推荐
发布评论