Basically:
Is it possible to prevent specific window
events from firing within JavaScript
running inside a WebView
? Specifically I want to prevent window.orientationchange
events being fired.
(Alternatively is there any way to be absolutely certain I am inside a WebView
and not in a normal Chrome/built-in browser window without overriding the User-Agent?)
In detail:
I've been tasked with embedding an existing web application inside a basic WebView
container on Android. The web app does not support portrait configurations, or browsers resized into a portrait aspect-ratio.
To fix that, there is a window.orientationchange
handler in the JavaScript
to detect this and display an error message if necessary.
For user-experience, we have the following Activity XML to prevent the user changing the orientation:
<activity
android:name="com.example.my-stackoverflow-app"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
android:screenOrientation="landscape">
This works perfectly. The trouble is, orientationchange
events get fired when pausing/resuming the Activity.
Since the Home Screen is portrait the window.orientationchange
handler is detecting this before the Activity re-orients itself and is locking me out of the app.
Naturally enough, a setTimeout
call fixes this, but there is a rather large sky-scraper outside my window which I will be visiting before resorting to a setTimeout
fix.