0

Is that even possible? I doubt it, but want to make sure.

typo.pl
  • 8,812
  • 2
  • 28
  • 29
dongshengcn
  • 6,434
  • 7
  • 35
  • 44

3 Answers3

2

If you're not allowed to write any Java code to perform this "orientation lock", then, no, it's not possible to lock the orientation of the app from JavaScript.

You could simulate 'locking' if you detected the orientation change as mentioned in the Detect rotation of Android phone in the browser with javascript link and readjusted your HTML accordingly. But that seems like a lot of work.

If you can use Java, then you can expose a Java object through the WebView.addJavascriptInterface method and write some JavaScript to get/set the orientation using the Activity.setRequestedOrientation and Activity.getRequestedOrientation methods.

Community
  • 1
  • 1
typo.pl
  • 8,812
  • 2
  • 28
  • 29
0

Why not? There's some simple trick coming to my mind... from Javascript you call the document.open() method with some custom url. On shouldOverrideUrlLoading view,url) you catch that call with your custom url, and so you do whatever you want.

Maybe I'm missing something... but I would try.

And well, I assume you already know that, but you have to use a WebView to embed some sort of web browser within your application.

==== EDIT ====
Well it seems I was missing something, and there is a much more classy way to do it. There is this tutorial (section Binding JavaScript code to Android code) which shows you how to add a JavaScriptAndroid interface, something related with what you want, if I'm not wrong. I haven't tried it, but it doesn't seem too difficult.

mdelolmo
  • 6,417
  • 3
  • 40
  • 58
0

At my work place, we had a similar issue with orientation changes in the device browser. We simply popped a modal window when the orientation changed. It informed the user to rotate the device back to continue. Seemed to work well on all our tested devices.

worked
  • 5,762
  • 5
  • 54
  • 79