Android, webview user agent vs browser user agent

前端 未结 7 962
眼角桃花
眼角桃花 2020-12-03 03:14

I\'m building my website and I want to know whether the user is using Android\'s browser or an app with a webview.

is it possible ??

相关标签:
7条回答
  • 2020-12-03 03:24

    FROM: http://googlewebmastercentral.blogspot.com/2011/03/mo-better-to-also-detect-mobile-user.html

    With a User-Agent like this:

    Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13

    since there is no “mobile” string, serve this user the desktop version (or a version customized for Android large-screen touch devices). The User-Agent tells us they’re coming from a large-screen device, the XOOM tablet.

    On the other hand, this User-Agent:

    Mozilla/5.0 (Linux; U; Android 2.2.1; en-us; Nexus One Build/FRG83) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1

    contains “mobile” and “android,” so serve the web surfer on this Nexus One the mobile experience!

    FROM https://stackoverflow.com/a/7327201

    it looks like the User-Agent is the same in webview as in the default mobile browser

    0 讨论(0)
  • 2020-12-03 03:24

    For more current information, look here https://developer.chrome.com/multidevice/user-agent The lolipop and newer devices include wv) in the UserAgent.

    0 讨论(0)
  • 2020-12-03 03:28

    You can used below code for checked android webview or browser.

    public static bool is_mobile_and_webview()
    {
         return System.Web.HttpContext.Current.Request.Browser.IsMobileDevice && System.Web.HttpContext.Current.Request.UserAgent.Contains("; wv");
    }
    
    0 讨论(0)
  • 2020-12-03 03:30

    FYI: This can't be done with user agents, however it can be detected. Android's web views send an addition header "X-Requested-With". The value of this header will be the application's name space that is running the webview.

    For Example Dolphin browser sends: "mobi.mgeek.TunnyBrowser" My test app sent: "com.jamestymann.identifyawebview"

    The standard browser actually does not send this header at all, so it is pretty easy to detect these.

    I have two caveats though:

    • "X-Requested-With" is a standard header and could potentially be sent from full blown webpages/browsers from desktops. (For example this is used to detect ajax calls with these values "X-Requested-With XMLHttpRequest")
    • Most google play store browsers use webviews to display webpages. Even though these are full blown browsers, they will still send this header. So if your intent is to disable this feature you may want to be careful as you may be disabling peoples default browsers.
    0 讨论(0)
  • 2020-12-03 03:38

    As per Chrome dev docs: "If you’re attempting to differentiate between the WebView and Chrome for Android, you should look for the presence of the Version/X.X string in the WebView user-agent string."

    0 讨论(0)
  • 2020-12-03 03:38

    I use this serverside, to access info about client' browser (agent) in PHP

    ...
    $_SERVER['HTTP_USER_AGENT']; // Different browsers ...
    ...
    

    this boilerplate can be interpreted - hence you will know the agent ...

    on client side - navigator.userAgent

    0 讨论(0)
提交回复
热议问题