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. Im not sure how to use the constant Full_Wake_Lock to keep the kb lgiht on.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You would need to start a Service
.
Then you would have to acquire the wake lock within the onCreate, then in the onDestroy you would release the 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.
回答2:
BEFORE: wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "DoNotDimScreen");
AFTER: wakeLock = pm.newWakeLock(PowerManager.ON_AFTER_RELEASE, "DoNotDimScreen");