2010-09-16 61 views

回答

1

你需要註冊一個BroadcastReceiver爲Intent.ACTION_SCREEN_OFF

因此,創建廣播接收器

這是你處理screen_off意圖。

private BroadcastReceiver receiver = new BroadcastReceiver() { 
public void onReceive(final Context context, final Intent intent) { 

    /* 
    * dispatch screen_off 
     * to handler method 
    */ 

    String iAction = intent.getAction(); 

    if (iAction.equals(Intent.ACTION_SCREEN_OFF)) 
    handleScreenAction(iAction); 

} 

}; 

現在過濾器註冊接收器。

static void registerReciever() { 
    IntentFilter myFilter = new IntentFilter(); 
    // Catch screen off event 
    myFilter.addAction(Intent.ACTION_SCREEN_OFF); 
    registerReceiver(receiver, myFilter); 
} 
+0

什麼也沒有發生 你能提供的完整代碼,請這將是一個很大的幫助 – James 2010-09-18 17:47:39

+0

你需要聲明的接收器在AndroidManifest.xml中了。 – 2011-06-08 12:40:02

+0

錯誤。這是清單中的接收方無法聲明的意圖之一。無論如何,你不想同時執行清單和代碼。 – 2011-06-15 14:15:15

相關問題