1

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.

Salamandar
  • 589
  • 6
  • 16

3 Answers3

2

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

Community
  • 1
  • 1
Jordan Junior
  • 1,090
  • 10
  • 11
2

You should use Broadcast Receiver for ACTION_SCREEN_ON, ACTION_SCREEN_OFF and ACTION_USER_PRESENT.

Read more here Android - detect phone unlock event, not screen on

Community
  • 1
  • 1
QArea
  • 4,955
  • 1
  • 12
  • 22
1

Well, in fact I found an answer myself :p

I didn't think about screen unlock (or turning on) before writing down my answer… And then I found this : http://thinkandroid.wordpress.com/2010/01/24/handling-screen-off-and-screen-on-intents/

I think it'll help me…

Salamandar
  • 589
  • 6
  • 16