我正在开发一个Android应用程序,如果屏幕已经开了很长时间,它会警告用户。这个应用程序的基本思想是警告用户眼睛会长时间暴露在屏幕上。我基本上想要打开屏幕灯的时间。如果达到一定的限制,用户将被通知关闭屏幕一段时间。
如何获得打开哪个屏幕的时间?
发布于 2014-04-24 04:30:22
看文件..。
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"
当屏幕打开时,跟踪当前时间,然后设置一段时间的警报,然后警告用户。
发布于 2014-04-24 04:31:26
您可以使用设备时间跟踪用户,并可以将其保存在SharedPreferences中以供进一步检查。
得到系统时间就像..。
// 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);
这在堆栈和谷歌上都有很多答案。
祝好运!
https://stackoverflow.com/questions/23259813
复制相似问题