Determine if the website is running in an Android browser or application web application

Update: thanks for the answers, but I want to clarify that I am a javascript developer and not an Android application developer, and I need to determine at runtime whether the site is loaded in the Android browser or loaded in the WebView application, only using javascript code

The original question: How does Javascript detect at runtime a website loading in the Android browser or loading in the WebView application if I am not responsible for the application?

+4
source share
2 answers

I believe that the user agent will be the same for both the browser and the web browser, not to tell the difference.

javascript Android . webview , .

, , .:

http://developer.android.com/guide/webapps/webview.html#BindingJavaScript

(Java/Javascript ):

@JavascriptInterface
public void userAgentDetect() {
    WebView = true;
}

WebView false, .

, WebView boolean , .

EDIT: : Android Browser WebView

+2

- WebView, - .

WebView :

//get current user agent
String userAgent = myWebView.getSettings().getUserAgentString();    
//add something
userAgent = userAgent + " my_website_is_in_a_webview";    
//save the new user agent
myWebView.getSettings().setUserAgentString(userAgent);
+1

Source: https://habr.com/ru/post/1569321/


All Articles