手机从 sleep 模式恢复后还能收到吗?我需要一个接收器。 OnScreenOn或交互式是检查屏幕是打开还是关闭。但我需要准确了解屏幕何时从 sleep 模式恢复。安卓。 API 23 及更高版本。
最佳答案
我不知道我是否理解正确,但似乎你需要一个 BroadcastReceiver
您可以在 this answer 中了解更多信息
为了完整起见,我将其添加到此处:
将以下内容添加到您的 list 中:
<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)) {
}
}
}
关于java - Android 如何获取手机是否从 sleep 模式恢复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45371367/