0

How can I get the remaining time until screenOff? I don't mean the value of timeout setting, but how much time remains until screenOff(if user haven't touch the screen). Some kind of checking every 2-3 secs.

dancer_69
  • 331
  • 2
  • 6
  • 20
  • I am not sure this is possible, you can register to receive the screen off intent but to get the time left I have no idea. – draksia May 24 '13 at 14:20
  • I already have a check for screen off. I want to use the time left though, so I need a way to check it – dancer_69 May 24 '13 at 14:23

1 Answers1

-1

You can get the default screen timeout set by the system using this:

android.provider.Settings.System.getInt(getContentResolver(),Settings.System.SCREEN_OFF_TIMEOUT,-1);

So you have the default timeout and the last time the user touched the device. With this you can approximate the time left for the screen to turn off.

Though i am not sure how you would handle user touches to the NotificationBar which would reset the timeout.

Sam
  • 3,413
  • 1
  • 18
  • 20
  • I have a timer which takes the default timeout value as start point. Basicaly I want to restart the timer, every time the timeout resets(after user touch). So I need a way to check when the timeout resets it's value. – dancer_69 May 24 '13 at 14:50
  • The timeout would reset it's value on one of the following scenarios: Incoming call, Touch on your App, Touch on the Notification bar. The first two are fairly simple to handle. The last is not possible in my opinion. Also if you want to do this from a service, with no touchable context of your application, i don't think it is possible at all. – Sam May 24 '13 at 15:03
  • this is not the answer. – Salman Khalid Mar 18 '20 at 22:27