Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
685 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...