I am creating a webapp and the user could only have acces with the android webview? Can i detect android webview with javascript?
Asked
Active
Viewed 1.0k times
5
-
3try this http://stackoverflow.com/questions/6783185/detect-inside-android-browser-or-webview – PresleyDias Mar 30 '12 at 12:08
-
try this library https://github.com/faisalman/ua-parser-js – maxi-code Sep 09 '19 at 22:16
3 Answers
4
From http://developer.android.com/guide/webapps/webview.html#EnablingJavaScript
For example, if you're developing a web application that's designed specifically for the WebView in your Android application, then you can define a custom user agent string with setUserAgentString(), then query the custom user agent in your web page to verify that the client requesting your web page is actually your Android application.

Marvin Emil Brach
- 3,984
- 1
- 32
- 62
3
var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
if(isAndroid) {
// Do something!
// Redirect to Android-site?
window.location = 'http://android.davidwalsh.name';
}

Hanush H Nair
- 119
- 1
- 5
-
4browser-apps would also detected which don't using the webview – Marvin Emil Brach Jul 31 '12 at 11:43
-
2it'll also detect android browsers, question is to detect if website is running inside webview through js. – Dr. DS Feb 20 '17 at 16:08
-
1It's not the right answer it also detect browers like Firefox or Chrome as 'android' . This is the only thing that works: https://stackoverflow.com/questions/6783185/detect-inside-android-browser-or-webview – Steven Nov 08 '17 at 13:35