Android, webview user agent vs browser user agent

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 ??

Solution #1:

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

Respondent: a fair player

Solution #2:

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.”

Respondent: Matthew

Solution #3:

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.
Respondent: Miguel Andres

Solution #4:

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

Respondent: jtymann

Solution #5:

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");
}
Respondent: Paul Gregoire

Solution #6:

yes and you can optimize your website by adding these meta tags

<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
<meta name="HandheldFriendly" content="True" />

you can find more information here http://learnthemobileweb.com/2009/07/mobile-meta-tags/

Respondent: alireza ahmadi

Solution #7:

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

Respondent: vin_mobilecem

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.