Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
681 views
in Technique[技术] by (71.8m points)

android - How to cancel AlarmClock that was created by my app?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...