Android: WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON question

不打扰是莪最后的温柔 提交于 2019-11-29 12:20:00

问题


Im using the following code to keep the screen on:

this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

Is there any way to disable/remove the FLAG_KEEP_SCREEN_ON later in the code? (I want the screen to fadeout normally).

Thanks!


回答1:


You could probably do something like this

this.getWindow().setFlags(this.getWindow().getFlags() & ~WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)

Did you look at the API? There's also this method

http://developer.android.com/reference/android/view/Window.html#clearFlags%28int%29

this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

I have not tried this either yet.

I imagine this will work to check if the flag is set:

this.getWindow().getFlags() & WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON

Edit: As per the comments, apparently this is how you get the value of the flag.

this.getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON

There might be a method for that too, you should look at the API doc.




回答2:


Try this

getWindow().clearFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

Also read this



来源:https://stackoverflow.com/questions/4620983/android-windowmanager-layoutparams-flag-keep-screen-on-question

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!