Intent intent = new Intent(alarmService.this, AlarmReceiver.class);
PendingIntent alarmIntent = PendingIntent.getBroadcast(alarmService.this, 0, intent, 0);
// AlarmReceiver.class 為當時間到達系統啟動的class, 該class 需 extends BroadcastReceiver
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND, 5);
//取得系統 service - ALARM_SERVICE
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
//註冊一個時間通知
am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),alarmIntent);
//取消一個時間通知
am.cancel(p_intent);
ALARM_SERVICE 指定時間通知
週一, 2011-03-21 15:06
#1
ALARM_SERVICE 指定時間通知