简体   繁体   English

[帮助]触摸Android中的接近传感器时关闭屏幕

[英][Help]Turn off the screen when touching the proximity sensor in Android

I want the screen will be turned off permanently but unlock when touching the proximity sensor and when untouching it, the screen will return to normal brightness (like in normal calls). 我希望屏幕将永久关闭,但在触摸接近传感器时将其解锁,而在不触摸它时,屏幕将恢复到正常亮度(就像在正常通话中一样)。 Now, I am using the way which has just blurred the screen without turning it off permanently. 现在,我使用的是模糊屏幕而不永久关闭屏幕的方法。

Window mywindow = getWindow();
WindowManager.LayoutParams lp = mywindow.getAttributes();
lp.screenBrightness = 0.01f;
mywindow.setAttributes(lp);

Hope for your help 希望对您有所帮助

Your choice will lower the brightness and hence it is blurred. 您的选择将降低亮度,因此模糊。 If u want to put the screen off, you have to make your app a device administrator and take the required permissions in manifest. 如果您想关闭屏幕,则必须让您的应用成为设备管理员,并在清单中获得所需的权限。

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

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