Android Alarm Clock - Remove alarms programmatically

后端 未结 2 562
旧时难觅i
旧时难觅i 2020-12-09 07:19

I am writing an application in which user can configure alerts/alarms. At this point, I have everything working expect the one. I am firing off an alarm using



        
相关标签:
2条回答
  • 2020-12-09 07:25

    As it was answered here: there is no supported API to this.

    Official documentation says that

    If a time of day is specified, and EXTRA_SKIP_UI is true, and the alarm is not repeating, the implementation should remove this alarm after it has been dismissed.

    But different manufactures implement their own alarm clocks and I'm not sure if someone supporrts this. I have tried it on JB emulator and looks like it dosen't work. Maybe, on KitKat? Only this one is ok on JB:

    If an identical alarm exists matching all parameters, the implementation may re-use it instead of creating a new one

    So, maybe, better solution is to use youre own alarm, created with AlarmManager or warn user that he has to remove Alarms by hands (to make it more obvious - not use AlarmClock.EXTRA_SKIP_UI).

    0 讨论(0)
  • 2020-12-09 07:50

    call method cancel(...) from AlarmManager, using the same PendingIntent you used to set the alarm. Example:

    mAlarmPendingIntent = PendingIntent.getActivity(this, requestCode, intent, flags);
    
    this.getAlarmManager().cancel(mAlarmPendingIntent);
    

    this refers to the Activity or the Service from which you are cancelling the alarm

    0 讨论(0)
提交回复
热议问题