如何使用闹钟类设置闹钟

8

您好,我正在尝试使用AlarmClock类在我的应用程序中设置闹钟。我正在使用以下代码:

 Intent intent = new Intent();
 intent.setAction(AlarmClock.ACTION_SET_ALARM);
 startActivity(intent);

但是我遇到了一个异常。请问有人可以告诉我如何使用这个新的Android功能吗?

3个回答

10

你还需要添加

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

添加到您的清单中。


9
奥利说得没错,代码应该长成以下这样:
Intent i = new Intent(AlarmClock.ACTION_SET_ALARM);
    i.putExtra(AlarmClock.EXTRA_HOUR, 9);
    i.putExtra(AlarmClock.EXTRA_MINUTES, 37);
    startActivity(i);

3

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接