Android: Get all PendingIntents set with AlarmManager

后端 未结 3 1931
傲寒
傲寒 2020-11-27 10:55

I\'m setting an alarm like this:

alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTime, pendingEvent);

I\'m interested in removing all the al

3条回答
  •  无人及你
    2020-11-27 11:16

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

提交回复
热议问题