1

I'm building a web app using Three.js (Javascript) and it's VR capabilities for mobile devices (android particullary). The issue I'm facing is that after some time screen gets dimmed and turned off. I was trying to find an API to keep the display on, but couldn't find any mention about it. However, if you go to http://vr.chromeexperiments.com/ and run any of those demos, the screen will be always on. I was trying to study their code but didn't find the solution. How do they do it? Thanks

Hamabama
  • 253
  • 1
  • 3
  • 10

2 Answers2

0

Add a flag in the onCreate method of your activity.

@Override
protected void onCreate(Bundle b) {
    super.onCreate(b);

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

Read more here.

Oscar
  • 3
  • 2
0

If you are running the app from any Browser (like chrome) is not possible to keep the screen awaken since you can't modify the device behavior via Javascript.

You can either get a third party app like KeepScreenOn (https://play.google.com/store/apps/details?id=com.nbondarchuk.android.keepscn&hl=es_419) to do that job or wrap the app inside a Webview using a hybrid App framework like PhoneGap or maybe Titanium. There you can use plug ins to do that job as well (like this one: https://build.phonegap.com/plugins/355)