嗨我想在我的應用程序中設置鬧鐘使用AlarmClock類。我使用的代碼如下:如何使用鬧鐘類設置鬧鐘
Intent intent = new Intent();
intent.setAction(AlarmClock.ACTION_SET_ALARM);
startActivity(intent);
但我收到一個異常。任何人都可以告訴如何使用這個android新功能。
在此先感謝。
嗨我想在我的應用程序中設置鬧鐘使用AlarmClock類。我使用的代碼如下:如何使用鬧鐘類設置鬧鐘
Intent intent = new Intent();
intent.setAction(AlarmClock.ACTION_SET_ALARM);
startActivity(intent);
但我收到一個異常。任何人都可以告訴如何使用這個android新功能。
在此先感謝。
您需要指定時間時,被設置了報警:
http://developer.android.com/reference/android/provider/AlarmClock.html
你問的Android爲小時&設置鬧鐘沒有告訴它的時候,所以添加額外的意圖束參數分鐘,然後我預計它會工作(很難確定,因爲你沒有提供有關例外的信息)。
奧利是正確的,代碼看起來應該像下面這樣:
Intent i = new Intent(AlarmClock.ACTION_SET_ALARM);
i.putExtra(AlarmClock.EXTRA_HOUR, 9);
i.putExtra(AlarmClock.EXTRA_MINUTES, 37);
startActivity(i);
您還需要
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
添加到您的清單。
爲什麼downvote? – barry 2013-10-25 20:19:56
什麼是例外? – 2011-02-14 07:31:07