Android AlarmClock ACTION_SET_ALARM intent produces exception

血红的双手。 提交于 2019-12-01 03:10:45

问题


The given example produces an Exception (android.content.ActivityNotFoundException: No Activity found to handle Intent)

Intent i = new Intent(AlarmClock.ACTION_SET_ALARM); 
i.putExtra(AlarmClock.EXTRA_MESSAGE, "New Alarm"); 
i.putExtra(AlarmClock.EXTRA_HOUR, hours); 
i.putExtra(AlarmClock.EXTRA_MINUTES, mins); 
startActivity(i); 

on my SGS2 Android Version 2.3.3. Do you have any ideas, what can be going wrong? An another intent request (e.g. selecting a contact from the address book) works fine.

Thank you, Artjom


回答1:


Do you have any ideas, what can be going wrong?

The device does not support that activity. This is not unheard of. Either catch the exception and let the user know, or use PackageManager and queryIntentActivities() to see if anything will respond to your Intent in advance of calling startActivity().




回答2:


You need to set permission in manifest file also.

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


来源:https://stackoverflow.com/questions/7305685/android-alarmclock-action-set-alarm-intent-produces-exception

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