0

Please help me to find the time duration of the screen state [ (i.e.,) Lock to Unlock duration]. Is there any pre-defined method available to achieve this?

Thanks in advance..

3 Answers3

0

I don't know that there is a pre-defined method for getting time elapsed while locked, but you could listen for broadcast intents that are fired when the device is locked/unlocked. See this question for the intents to register for: Android launch intent when lockscreen should appear

In your broadcast receivers, you can keep track of the time elapsed while locked.

Community
  • 1
  • 1
Samuel
  • 16,923
  • 6
  • 62
  • 75
0

I don`t know if that is what you are looking for, but you can read the "Screen timeout" (in ms) like this:

android.provider.Settings.System.getInt(activity.getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, 0);

it`s possible to set the "Screen timeout" like this:

android.provider.Settings.System.putInt(activity.getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, 30 * 1000); // 30 seconds

Your app will need the following permission:

<uses-permission android:name="android.permission.WRITE_SETTINGS" />
malimo
  • 770
  • 6
  • 7
0

You can start a service that initiates a timer when the screen gets locked and upon unlocking the screen, you can calculate the time.. We have a broadcast for this.. Or, you can also use AlarmManager for this.

Abhishek Shukla
  • 1,242
  • 8
  • 11