我正在製作鬧鐘應用程序。這個應用程序在警報處於活動狀態(由日曆激活)時調用一個意圖。當鬧鐘或日曆關閉時,我想打電話給hello.class
。這個類在被日曆調用的未決意圖中提及。當日歷被調用並且待處理的意圖應該被處理時,根本沒有任何事情發生。關於我做錯什麼的想法?Android日曆意圖
我的代碼如下:標有「ABC」的註釋該生產線是其中hello.class
提到
Intent myIntent = new Intent(AndroidAlarmService.this, Hello.class); // ABC
pendingIntent = PendingIntent.getService(AndroidAlarmService.this, 0, myIntent, 0);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND, 5);
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
這或許能有所幫助:HTTP://stackoverflow.com/questions/3052149/using-alarmmanager-在特定時間啓動服務 –