androidandroid-serviceuser-inactivity

How to detect user inactivity?


I'd like to run a service/background task that would detect user inactivity (that would be touching the screen or unlock the phone).

It would be used to detect that the phone is lost, and then send position informations to a server. Automatically (oh yeah).

How could I detect that ?

Thanks.


Solution

  • I think you need a background service to look if the android is not on user presence.

    You can use android sensors, like Accelerometer, to detect if the phone is active. (if someone get the phone, the sensors will change) And, you will need and wake up the service, in a regular amount of time, to check if the sensor has changed. If the sensor not changed at all in a large amount of time, the phone was lost.

    Look at this: How to detect user presence in android?

    And this: https://developer.android.com/training/run-background-service/index.html