2

I am currently working on an app that utilizes the light sensors to perform a task in my service. I used the examples from this site as my base:

Android Light Sensor

The sensors work perfectly when my tablet is plugged into the computer to debug. However, if I run the same code without it being plugged in, the response is super slow, and some times never triggers at all.

Can anyone suggest why the performance is hindered when the device is by itself?

EDIT: I SHOULD HAVE NOTED THAT I AM TRYING TO READ THE SENSOR WITH THE DEVICE OFF. I FOUND THAT THE PROBLEM WAS THAT THE SENSOR WAS SHUTTING DOWN WHEN THE DEVICE SLEPT. PLEASE SEE MY ANSWER BELOW.

Thanks, josh

2 Answers 2

1

Sometimes this is just a device issue, many have been reported as acting slow to light/proximity sensors. As far as the anomaly of the sensors responding normally when it is plugged in; maybe your device sensors simply respond faster when there is a power source.

I'd say look through your options with changing the rate

In:

https://developer.android.com/reference/android/hardware/SensorManager.html

rate rate of events. This is only a hint to the system. events may be received faster or slower than the specified rate. Usually events are received faster. The value must be one of SENSOR_DELAY_NORMAL, SENSOR_DELAY_UI, SENSOR_DELAY_GAME, or SENSOR_DELAY_FASTEST.

So I would imagine adding SENSOR_DELAY_FASTEST may help you.

Also, I refer you to Android SENSOR_DELAY_FASTEST isn't fast enough post.

7
  • I tried adjusting the sensor delay, but this had no effect when unplugged. I believe you are right that it may possibly that the sensors are faster when powered. However, I hope this is not the case as it makes using the light sensor for my app a null point.
    – Josh
    Jan 30, 2012 at 4:56
  • If that is true, best case scenerio is you continue with what you have and have a disclaimer: Android 3.1 has known sensor issues or something like that...and most devices will be moving away from that version so it may not be much of an issue in the long run. Jan 30, 2012 at 5:18
  • So to test the sensor power theory, I tried the app with the tablet plugged into the wall rather than the PC. The result was the same slow result as when it's not plugged in. So it is something to do with the PC apparently. It doesn't matter if my development environment is running either, as it is just as fast without Eclipse running.
    – Josh
    Jan 30, 2012 at 10:51
  • 1
    I've assured the amount of lighting isn't the culprit through my code. I now believe it has something to do with the sensor going to deep sleep, but only when it is unplugged (my app reads the light when the device is sleeping). I've noticed their are some threads here on this, and will keep this updated if I manage to fix it.
    – Josh
    Jan 30, 2012 at 11:17
  • 1
    Partial Wake Lock seems to have done the trick, although I am not sure if it is worth the cost to the battery. I will monitor throughout the day. Thanks for all of your suggestions.
    – Josh
    Jan 30, 2012 at 11:56
1

I found that the cause of the trouble was the device shutting the CPU down, which resulted in delay or non-reading of the light sensor.

Adding a partial wake lock did fix the problem, but at the cost of high battery usage. If anyone has any suggestions as to how I can continue monitoring the light sensor with the device off without the Wake Lock I would greatly appreciate it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.