How to set Alarm using alarm clock class

前端 未结 3 565
北海茫月
北海茫月 2020-12-30 12:36

Hi I am trying to set Alarm in my application Using the AlarmClock class. I am using the code as follows:

 Intent intent = new Intent();
 intent.setAction(Al         


        
相关标签:
3条回答
  • 2020-12-30 12:38

    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).

    0 讨论(0)
  • 2020-12-30 12:51

    You'll also need to add

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

    to your manifest.

    0 讨论(0)
  • 2020-12-30 12:59

    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);
    
    0 讨论(0)
提交回复
热议问题