I am developing an application which should detect user movement and when he stops for more than 5 minutes it should sound an alarm. I was able to detect movement with accelerometer but the problem is it doesnt work when the screen is off. I have also tried using partial wakeLock. Re-registering accelerometer doesnt work either (this should be workaround for motorola devices).
Maybe I can do this using GPS and sound an alarm when GPS speed is less than 1m/s for more than 5 minutes but I am not sure if I will receive GPS updates when screen is off.
So I need a solution that will detect user movement even is screen is off on most devices. Any ideas on how to acomplish this?
Thanks in forward
You should acquire a partial
wake lock
for this kind of operation. Use the PowerManager class.Something like this:
You need also this permission in the
AndroidManifest.xml
:Is recommendable using
lock.release();
when you're done your work.EDIT:
Also, this article could be useful for you.
partial wake lock this is what you need to access while your screen is off.
And after you're done, just release the lock:
If you obtain accelerometer data in a Service, you could simply acquire lock in it's onCreate() and release in onDestroy().