0

I want to use light sensor to detect the environment of phone changing, then protect the phone from being stolen. But I don't know whether, if the screen is turned off, the sensor still works or not. And, can anybody make some suggestions how can I make this goal? If I register a sensor in the service, will i make it?

I know that, using context.getSystemService(SENSOR_SERVICE), I can get the sensormanager, register the sensor, and implement the SensorEventListener. Through the sensorevent.value I can get the value of lightsensor.

CocoNess
  • 4,045
  • 4
  • 23
  • 41
honeypig
  • 39
  • 4

1 Answers1

0

Yes you can actually use the sensor API here. Even if the screen is not active, the sensor will still work. But be careful, so as not to have it go on for a long time. As this will drain enormous battery power and reduce battery longevity .

"Always make sure to disable sensors you don't need, especially when your activity is paused. Failing to do so can drain the battery in just a few hours. Note that the system will not disable sensors automatically when the screen turns off."

"To optimize our app for performance, it is the best practice to get the notifications just while your app is in running state."

The Dark Knight
  • 4,986
  • 10
  • 42
  • 86