我使用以下代码在特定日期设置闹钟。
我应该在Android清单中加入什么来保持警报功能,即使在关机后以及关机后仍然可以开启?
Calendar cal = Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault());
//cal.add(Calendar.SECOND, 10);
cal.set(Calendar.DATE,19); //1-31
cal.set(Calendar.MONTH,Calendar.DECEMBER); //first month is 0!!! January is zero!!!
cal.set(Calendar.YEAR,2012);//year...
cal.set(Calendar.HOUR_OF_DAY, 16); //HOUR
cal.set(Calendar.MINUTE, 39); //MIN
cal.set(Calendar.SECOND, 10); //SEC
// Create a new PendingIntent and add it to the AlarmManager
Intent intent = new Intent(MainActivity.this, alarmAct.class);
PendingIntent pendingIntent = PendingIntent.getService(MainActivity.this, 0,intent, 0);
//or if you start an Activity
//PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0,intent, 0);
AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);
我已将此添加到清单:
<service android:name=".MyAlarmService" />
有人知道如何使用RTC_WAKEUP
吗?
:)
答案 0 :(得分:2)
您需要注意的是注册使用该操作的BroadcastReceiver
<action android:name="android.intent.action.BOOT_COMPLETED" />
在该接收器中,您可以开始备份警报和所需的任何服务