关闭/ Android的屏幕上 [英] Turn off/on android screen
本文介绍了关闭/ Android的屏幕上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图把Android的屏幕关闭,然后再打开,几秒钟后。 关闭的部分作品,与此code:
I am trying to turn the android screen off and then on again, after a few seconds. The "turn off" part works, with this code:
WindowManager.LayoutParams layoutParam = getWindow().getAttributes();
oldBrightness = android.provider.Settings.System.getInt(getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS)/255f;
layoutParam.screenBrightness = 0;
layoutParam.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
getWindow().setAttributes(layoutParam);
但后来,当我尝试打开屏幕再次,它不会与此code工作:
But then, when I try to turn the screen on again, it does not work with this code:
WindowManager.LayoutParams layoutParam = getWindow().getAttributes();
layoutParam.screenBrightness = oldBrightness;
layoutParam.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
getWindow().setAttributes(layoutParam);
任何想法来解决?
Any idea to solve that ?
感谢
推荐答案
我觉得你可以试试PowerManager的激活锁定也许会奏效。我米用在我的应用程序这个code。和它的作品很好。 :)
I think U can try Powermanager WakeLock maybe it will work. I m using this code in my application. and it works well. :)
此外ü需要设置权限清单中。
Also u need to set permission in manifest.
<uses-permission android:name="android.permission.WAKE_LOCK"/> // Manifest Permission
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
WakeLock wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK
| PowerManager.ACQUIRE_CAUSES_WAKEUP
| PowerManager.ON_AFTER_RELEASE, "MyWakeLock");
wakeLock.acquire();
这篇关于关闭/ Android的屏幕上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文