Search code examples
androidandroid-serviceforegroundandroid-sensors

Problem with sensors in a service


i've a foreground service that read Accelerometer and Orientation sensors, and send a sms when the phone it's moved.

It works fine when the display is turned on, but when not it not works or it send the sms after lot of times.

There is a broadcastreceiver in the service for reading incoming sms that works fine, if i send the command "status" its reply correctly.

What's the problem?

Thanks!


Solution

  • You need to acquire a wake lock to continue receiving sensor events.

    http://developer.android.com/reference/android/os/PowerManager.html

    I suggest a partial wake lock.