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..
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..
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.
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" />
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.