如果手机从睡眠模式回来,可以接收吗?我需要一个接收器。 OnScreenOn或interactive是检查屏幕是On还是Off。但是当屏幕从睡眠模式回来时我需要准确到达。 Android系统。 API 23及以上。
答案 0 :(得分:0)
我不知道我是否理解正确,但您似乎需要BroadcastReceiver
为了完整起见,我将在此处添加:
将以下内容添加到您的清单中:
<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)) {
}
}
}