In HTML5, how can I keep an Android device’s screen on?

前端 未结 5 1639
挽巷
挽巷 2020-12-06 05:37

We are developing an App in HTML5 using jQuery.

Is there a way/method, in JavaScript or another technology, to keep the screen \"on\"?

5条回答
  •  没有蜡笔的小新
    2020-12-06 06:16

    There is no way to ONLY write javascript or other web code to keep the screen on, without writing at least a little java code.

    To explain why I am so certain, if you are developing a web app through html5 you MUST use a WebView as the main "screen" of your application to host your html,javascript code. So your "web code" does not directly run in the application but uses a View as its holder. As you can guess you can't just lock the screen from some code that is not even running in the native part.

    I can provide a very easy and simple way to keep the screen on if you are not an expert in android programming. In the first activity, that uses the WebView I guess, add in onCreate after super:

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

提交回复
热议问题