2013-03-28 145 views
0

在我的項目中,我有一個連接到HTTP的服務來查看它是否在線。 一切正常,它連接。AlarmManager with RTC_WAKEUP does not wake device

問題是當我的設備進入睡眠狀態時。

我用AlarmManager觸發事件的檢查,使用RTC_WAKEUP,使得運行過程中,即使屏幕處於關閉狀態......

的問題是,這是不是真的發生了。 我創建了一個記錄方法來查看我的應用程序的窗簾後面發生了什麼。

我記錄了每一步,寫下它發生的時間,看看事件發生的時間和方式。

當我將設備設置爲睡眠狀態並在幾分鐘後回來時,我可以看到只有在喚醒設備時纔會觸發鬧鐘,而不會在睡眠時觸發鬧鐘。

這裏是我創建報警代碼:

public static void AddAlarm(Context pContext, Server pServer) 
{ 
    // Create pending with intent and server object with a helper that creates my pending intent. 
    PendingIntent pending = IntentGenerator.GetPendingIntentForAlarm(pContext,pServer.ServerId); 

    // Get alarm manager 
    AlarmManager alarm = (AlarmManager)pContext.getSystemService("alarm"); 

    // Get current time to start now. 
    long startNow = new Date().getTime()-10; 

    // Set repeating alarm with current time to start, and interval. 
    alarm.setRepeating(AlarmManager.RTC_WAKEUP ,startNow, pServer.GetIntervalInMilliseconds(), pending); 
} 

而如果你想知道如何創建掛起的意圖:

public static Intent GetIntentForService(Context pContext, int pServerId) 
{ 
    // Comienzo la alarma. 
    Intent retVal = new Intent(pContext, ServerStatusCheckService.class); 
    retVal.putExtra("SERVER_ID", pServerId); 

    return retVal; 
} 

回答

0

我想這個問題是我自己的設備。 這是一款Zenithink C93平板電腦。 我在摩托羅拉Defy上測試了相同的代碼,並且完美運行。

相關問題