简体   繁体   English

如何在android4.0中使用常量Full_Wake_Lock?

[英]How do i use the constant Full_Wake_Lock in android4.0?

Im trying to create a program to keep the keyboard backlight on if the screen is on. 我试图创建一个程序来保持键盘背光(如果屏幕打开)。 Im very new to android but i have been programming java for 6months. 我对android非常陌生,但是我已经为Java编程了6个月。 Im not sure how to use the constant Full_Wake_Lock to keep the kb lgiht on. 我不确定如何使用常量Full_Wake_Lock保持kb lgiht处于打开状态。

BEFORE: wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "DoNotDimScreen"); 之前: wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "DoNotDimScreen");

AFTER: wakeLock = pm.newWakeLock(PowerManager.ON_AFTER_RELEASE, "DoNotDimScreen"); 之后: wakeLock = pm.newWakeLock(PowerManager.ON_AFTER_RELEASE, "DoNotDimScreen");

You would need to start a Service . 您将需要启动Service
Then you would have to acquire the wake lock within the onCreate, then in the onDestroy you would release the WakeLock. 然后,您将必须在onCreate中获取唤醒锁,然后在onDestroy中释放WakeLock。 That is if you are trying to hold the wake lock from the background. 也就是说,如果您尝试从后台持有唤醒锁。

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Tag");
wl.acquire();

that is to gain it, and then to release it: 那就是获得它,然后释放它:

wl.release();

And of course, you would want to declare wl within the class body outside of any methods. 当然,您可能想在任何方法之外的类体内声明wl

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM