Android的AlarmClock的强制力接近Android、AlarmClock

2023-09-12 23:45:51 作者:猫一样的女子

我正在写一个应用程序,设置一个报警,和这里的相关code这是造成一个强制关闭:

I'm writing an app that sets an alarm, and here's the relevant code that's causing a force close:

Intent i = new Intent(AlarmClock.ACTION_SET_ALARM);
i.putExtra(AlarmClock.EXTRA_HOUR, hours);
i.putExtra(AlarmClock.EXTRA_MINUTES, minutes);
i.putExtra(AlarmClock.EXTRA_SKIP_UI, true);
startActivity(i);

startActivity(我)引起的力接近。我试图捕捉 ActivityNotFoundException 键,显示敬酒,但部队密切仍在进行之中。

The startActivity(i) is causing the force close. I tried catching ActivityNotFoundException and displaying a Toast, but the force close is still happening.

我真的很新的到Android编程,和我开始觉得有其他的力量在这里工作......确实清单文件需要被编辑考虑到活动不是天然的这个应用程序(如闹钟),这个应用程序会尝试启动?

I'm really new to Android programming, and I'm starting to think there are other forces at work here... does the manifest file need to be edited to account for Activities not native to this application (such as the Alarm Clock) that this application tries to start?

编辑:我应该提到,我使用的是Android 2.3.5(API 10级)

I should have mentioned, I'm using Android 2.3.5 (API level 10).

推荐答案

如果您的API是9 +

If your API is 9+,

然后用此权限在你的清单文件,

Then use this permission in your manifest file,

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

编辑:

看看这个网页。机器人 - AlarmClock的