0
我正在編寫一個應用程序,並且讓我的鬧鐘BroadcastReceiver無法啓動所需的意圖。代碼如下:Android - 啓動Wackelock的鬧鐘未啓動意向服務
public void onReceive(Context context, Intent intent)
{
Log.d("Alarm:","Running WakeLock");
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "");
wl.acquire();
WakeMe.wakelock = wl;
Log.d("Alarm:","Running Intent (Service)");
Intent i = new Intent(context, serviceCode.class);
context.startService(i);
}
public void SetAlarm(Context context)
{
AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, Alarm.class);
PendingIntent pi = PendingIntent.getService(context, 1, i, 0);
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 60000, pi); // Millisec * Second * Minute
Log.d("Alarm:", "Alarm set to run every 1 minute/s");
}
當SetAlarm()被調用的代碼運行的onReceive()和通過serviceCode類運行時,它也設置報警向上並運行報警每1分鐘。我發現的問題是,當警報觸發並運行喚醒鎖時,它不會啓動serviceCode並運行。相反,它只是忽略了新的意圖。
注意:wakelock在serviceCode結束時釋放。
任何幫助將apreciated
謝謝你,我用你的WakefulIntentService,它似乎很好。然而,我確實需要調整AlarmReceiver,以便檢查在啓動時是否連接了電源,我希望這對您有好處。 – PaX