How to set Alarm using alarm clock class

时间秒杀一切 提交于 2019-11-30 07:14:01

You'll also need to add

<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>

to your manifest.

Ollie is right, the code should look something like the following:

Intent i = new Intent(AlarmClock.ACTION_SET_ALARM);
    i.putExtra(AlarmClock.EXTRA_HOUR, 9);
    i.putExtra(AlarmClock.EXTRA_MINUTES, 37);
    startActivity(i);

You need to specify the time when the alarm is being set for:

http://developer.android.com/reference/android/provider/AlarmClock.html

You're asking Android to set an alarm without telling it when, so add extra intent bundle parameters for Hour & Minutes and then I expect it will work (it is hard to be sure as you've provided no information about the exception).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!