bluediapente bluediapente - 10 days ago 6
Android Question

Android: Get all PendingIntents set with AlarmManager

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 ?

Answer

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