如何获得屏幕打开的时间

时间:2023-01-22 23:08:02

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.

我正在开发一个Android应用程序,如果屏幕已经打开了很长时间,它将警告用户。该应用程序背后的基本思想是警告用户眼睛长时间暴露在屏幕光线下。我基本上想要屏幕灯打开的时间。如果达到某个限制,则会通知用户将屏幕关闭一段时间。

How to get the time for which screen is turned ON?

如何获得打开屏幕的时间?

2 个解决方案

#1


5  

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.

当屏幕打开时,跟踪当前时间,然后设置一段时间的警报,然后警告用户。

#2


0  

You can track user with device time and can save same in SharedPreferences for further checks ..

您可以使用设备时间跟踪用户,并可以将其保存在SharedPreferences中以进行进一步检查。

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!

祝你好运!

#1


5  

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.

当屏幕打开时,跟踪当前时间,然后设置一段时间的警报,然后警告用户。

#2


0  

You can track user with device time and can save same in SharedPreferences for further checks ..

您可以使用设备时间跟踪用户,并可以将其保存在SharedPreferences中以进行进一步检查。

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!

祝你好运!