2017-07-28 60 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

嗨,但问题是,它只是在设备重新启动一次后才起作用。 –

相关问题