How to cancel AlarmClock that was created by my ap

2019-01-29 02:48发布

问题:

I am creating an app which intends to create an alarm just to wake up the user. I did not use the AlarmManager because I do not need the app to run any code or function once the alarm goes off. So, the end goal of my app is to set the phone's native alarm. For this, I used the AlarmClock class like so:

Intent intent = new Intent(AlarmClock.ACTION_SET_ALARM);
intent.putExtra(AlarmClock.EXTRA_HOUR, hour);
intent.putExtra(AlarmClock.EXTRA_MINUTES, minute);
intent.putExtra(AlarmClock.EXTRA_SKIP_UI, false);
startActivity(intent);

I would like to have the functionality to cancel the alarm. How can I access the set alarms via the app code?

Note: The alarm does not show up in the alarm clock widget on the native home screen, but appears in the native Clock application.

回答1:

Since the AlarmClock class doesn't expose a public action for this, there is no supported way to do this programmatically. The expectation is probably that users will do it via the UI. If you want more control, use AlaramManager and set/clear your own alarms.