Prevent screen lock on dimming/standby while using android app?

时间秒杀一切 提交于 2019-12-01 06:16:42

问题


I'm developing an application and the last touch I need to put on it is preventing the screen to lock when the device goes into standby (screen off). The exact behavior as Google Navigation.

I'm wondering what, programatically I will have to use to keep this feature enable the entire time while using the app?


回答1:


writing the following code to your xml file will prevent the screen from locking

android:keepScreenOn="true"



回答2:


In the onCreate of your activity after the setContentView use this:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

Not tried it myself.



来源:https://stackoverflow.com/questions/10446299/prevent-screen-lock-on-dimming-standby-while-using-android-app

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