0

Is there a way to track the amount of time an individual doesn't use their cell phone? For example, let's say I used my phone and decided to lock it (not use it for any given amount time).

Would there be a way to track this? I've tried looking this up but came short. My apologies in advance if this question seems a bit vague.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
sp92
  • 873
  • 1
  • 6
  • 17

2 Answers2

1

I won't go into details, but on Android you can make a Service listening for broadcast events SCREEN_ON and SCREEN_OFF. See this answer. You can then note the time between the events to figure out the amount of time the phone is on or off.

On iOS, I did a bit of research and it doesn't seem easily done. There already a question about it here which also mentions how to do it on Android.

Nicolas
  • 6,611
  • 3
  • 29
  • 73
  • gotcha, thanks man. have a good day. – sp92 Jun 13 '18 at 19:23
  • In Android 8+ this broadcast no longer works. – Marc Estrada Jun 13 '18 at 19:27
  • I think this no longer works only when declared in the manifest, but it works for a service. Here's a one that does that from Google: https://github.com/google/physical-web/blob/master/android/PhysicalWeb/app/src/main/java/org/physical_web/physicalweb/ScreenListenerService.java – Nicolas Jun 13 '18 at 19:31
  • Yes you're right, but services in Android 8+ must be in foreground, which means permanent ongoing notification. And in most of cases the developer doesn't want a permanent foreground service. – Marc Estrada Jun 13 '18 at 21:05
0

For Android:

You can do so by registering a broadcast receiver to the following intent actions

android.intent.action.SCREEN_OFF
android.intent.action.SCREEN_ON

and find out the elapsed time since the user last used his phone in the onRecieve() of the receiver.

This answer to a similar situation can be of help

android: broadcast receiver for screen on and screen off

Community
  • 1
  • 1
madking
  • 595
  • 3
  • 12