Reputation: 171
I am working on an Android application which will warn the user if the screen is been ON for a long time. The basic idea behind the app is to warn the user about the long exposure of eyes to the screen light. I basically want the time for which the screen light is turned ON. If it reaches a certain limit then, the user will be notified to turn the screen OFF for some time.
How to get the time for which screen is turned ON?
Upvotes: 2
Views: 107
Reputation: 3596
You can track user with device time and can save same in SharedPreferences for further checks ..
Get system time like ..
// using Calendar class
Calendar ci = Calendar.getInstance();
String CiDateTime = "" + ci.get(Calendar.YEAR) + "-" +
(ci.get(Calendar.MONTH) + 1) + "-" +
ci.get(Calendar.DAY_OF_MONTH) + " " +
ci.get(Calendar.HOUR) + ":" +
ci.get(Calendar.MINUTE) + ":" +
ci.get(Calendar.SECOND);
There's lot of answer for this available on stack and Google as well ..
good luck!
Upvotes: 0
Reputation: 13541
Reading the documentation...
public static final String ACTION_SCREEN_OFF
Added in API level 1
Broadcast Action: Sent after the screen turns off.
This is a protected intent that can only be sent by the system.
Constant Value: "android.intent.action.SCREEN_OFF"
public static final String ACTION_SCREEN_ON
Added in API level 1
Broadcast Action: Sent after the screen turns on.
This is a protected intent that can only be sent by the system.
Constant Value: "android.intent.action.SCREEN_ON"
When the screen is turned on keep track of the current time and then set an alarm for a certain period of time and then warn the user.
Upvotes: 5