2017-07-28 59 views
-1

如果手機從睡眠模式返回,將可以接收數據?我需要一個接收器。 OnScreenOn或交互式是檢查屏幕是否開啓或關閉。但是我需要確切地知道屏幕何時從睡眠模式返回。 Android系統。 API 23及以上。如何獲取手機是否從睡眠模式返回Android

+0

如果手機從睡眠模式返回,您是否需要等待?我需要一個接收器。 OnScreenOn或交互式是檢查屏幕是否開啓或關閉。但是我需要確切地知道屏幕何時從睡眠模式返回。 Android系統。 API 23及以上。 –

+0

什麼電話?你是Android嗎? –

+0

三星s6 edge Android 7.0-7.1.2 –

回答

0

我不知道如果我理解正確的你,但好像你需要一個BroadcastReceiver

你有this answer

更多信息爲了完整起見,我將在這裏添加:

以下內容添加到您的清單:

<receiver android:name=".UserPresentBroadcastReceiver"> 
    <intent-filter> 
    <action android:name="android.intent.action.USER_PRESENT" /> 
    <action android:name="android.intent.action.ACTION_SHUTDOWN" /> 
</intent-filter> 
</receiver> 

手柄的操作:

import android.content.BroadcastReceiver; 
import android.content.Context; 
import android.content.Intent; 

public class UserPresentBroadcastReceiver extends BroadcastReceiver { 

    @Override 
    public void onReceive(Context arg0, Intent intent) { 

     /*Sent when the user is present after 
     * device wakes up (e.g when the keyguard is gone) 
     * */ 
     if(intent.getAction().equals(Intent.ACTION_USER_PRESENT)){ 

     } 
     /*Device is shutting down. This is broadcast when the device 
     * is being shut down (completely turned off, not sleeping) 
     * */ 
     else if (intent.getAction().equals(Intent.ACTION_SHUTDOWN)) { 

     } 
    } 

} 
+0

感謝它的工作非常好 –

+0

請考慮標記答案是正確的 – Pelocho

+0

嗨,但問題是,它只是在設備重新啓動一次後才起作用。 –

相關問題