My app simply need to detect any motion of the device while screen is off.
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?
Motion can be detected by monitoring changes in: Infrared light (passive and active sensors) Visible light (video and camera systems) Radio frequency energy (radar, microwave and tomographic motion detection)
The Android platform provides several sensors that let you monitor the motion of a device. The sensors' possible architectures vary by sensor type: The gravity, linear acceleration, rotation vector, significant motion, step counter, and step detector sensors are either hardware-based or software-based.
Use Motion Detector Android App Motion Detector app is another free Android third-party application that offers motion detection with the help of your phone's camera. This is a simple app that shows the number of times motion is detected through your camera and also takes photos of the motion to save it on your device.
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();
If you obtain accelerometer data in a Service
, you could simply acquire lock in it's onCreate()
and release in onDestroy()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With