Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Identify if sensor works when screen is OFF in android

I want to identify if the Sensor used for Activity Recognition works when device screen is off.

Activity Recognition stops as soon as Device screen is turned OFF. I searched for it and found that sensor does not work when screen is OFF to save the battery.

So there is a method to identify such sensors by isWakeUpSensor(), but isWakeUpSensor() is applicable from API 21.

How can I make it work on API 14 onward. Identify sensor before starting Activity Recognition. Same as application "Moves" does

like image 518
Sagar Patil Avatar asked Aug 17 '15 07:08

Sagar Patil


1 Answers

After a little bit of searching I found this documentation which states

Up to KitKat, whether a sensor was a wake-up or a non-wake-up sensor was dictated by the sensor type: most were non-wake-up sensors, with the exception of the proximity sensor and the significant motion detector.

On the other hand, the significant motion detector page says

Implement only the wake-up version of this sensor. getDefaultSensor(SENSOR_TYPE_SIGNIFICANT_MOTION) returns a non-wake-up sensor

which confuses me. It is, however, a composite sensor, which means that it's wake-up-ness depends on the underlying actual sensors (I would imagine).

More research into this suggests that significant motion detector was added in Android 4.3 (API 18), so you're left with the proximity sensor for available wake-up sensors in API 14 devices, which is primarily intended to be used to turn the screen on and off when making phone calls.

Seems to me like there is no way to do exactly what you have in mind without a wake lock.

like image 99
Zharf Avatar answered Sep 28 '22 01:09

Zharf