我正在使用以下代码在特定日期设置警报。
我应该在 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
吗?
:)