是否有可能检测到运动时屏幕关闭? [英] Is it possible to detect motion when screen is off?

查看:231
本文介绍了是否有可能检测到运动时屏幕关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序只需要检测到设备的任何运动,而屏幕​​是关闭的。

My app simply need to detect any motion of the device while screen is off.

我知道,加速度计用于此任务,但同时屏幕关闭所有设备中它不工作。这是设备的列表 http://www.saltwebsites.com/2012/android -accelerometers屏​​幕关闭

I know that accelerometer is used for this task but it don't work while screen is off in all devices. this is a list of devices http://www.saltwebsites.com/2012/android-accelerometers-screen-off

所以有服用加速度传感器数据的方式,而屏幕是关闭了所有设备的工作原理?

so is there a way of taking accelerometer sensor data while screen is off that works on all devices?

还是有办法使用另一个传感器来检测运动?

or is there a way to detect motion using another sensors?

推荐答案

部分唤醒锁定 是所有你需要访问加速度计读数而屏幕是关闭的。

Partial Wake Lock is all you need to access accelerometer readings while the screen is off.

您可以使用它是这样的:

You can use it like this:

private PowerManager.WakeLock mWakeLock;

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My Tag");
mWakeLock.acquire();

和大功告成后,就释放锁:

And after you're done, just release the lock:

mWakeLock.release();

如果您在 获得加速度数据服务 ,你可以简单地获得锁在它的的onCreate()发布的onDestroy()

这篇关于是否有可能检测到运动时屏幕关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆