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
Asked
Active
Viewed 232 times
2 Answers
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
-
Sorry. I should have state it more clear. I'm writing an app using javascript. – Hamabama Dec 04 '14 at 21:22
-
Is it a mobile web app or is it wrapped in an Android project using a WebView? – Oscar Dec 05 '14 at 23:43
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)

Cesar Alvarado
- 121
- 3
-
So how Google does it then? It is a web app running from browser. Thanks for the links though. – Hamabama Dec 04 '14 at 21:43