Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android mobile user agent?

I'm currently making an android application for a forum, basically it just loads the website in a webview and that works fine and all, but I'm trying to add an option to view the full site or the mobile site.

I got it working by just making a boolean BrowserType which when set to true, loads the mobile site in the webview, and when set to false, loads the full page. I already have it working and everything, the full site loads and I jsut have the user agent as "Chrome", and I set the mobile user agent to "Mobile", but that doesn't work, what am I supposed to use as the user agent for mobile? Just for reference, this is the method I'm using:

myWebView.getSettings().setUserAgentString("Chrome");

Then for the mobile one instead of "Chrome", I used "Mobile". What is the correct user agent for mobile?

like image 213
Darren Avatar asked Sep 06 '11 23:09

Darren


People also ask

What is the Android user agent?

The User-Agent (UA) string is contained in the HTTP headers and is intended to identify devices requesting online content. The User-Agent tells the server what the visiting device is (among many other things) and this information can be used to determine what content to return.

Do mobile apps have user agents?

Apps often use the same online resources as the web site like RESTful APIs, images or videos. Because these resources are shared, it is very important to correctly form User-Agents for mobile apps to identify who is using the resources.

How do I change the user agent on my Android phone?

Tap “User agent” at the top of the “Customize” sub-section of the “Advanced” tab. Select one of the four built-in user agents or tap “Custom” and enter your own value, then tap “OK” to save. Tip: There are no rules governing the value of the user agent, so feel free to enter any value you want.

What does my user agent mean?

Definition: A user agent is any software that retrieves, renders and facilitates end user interaction with Web content, or whose user interface is implemented using Web technologies.


2 Answers

This is an example of user agent for android:

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

And you can use simply:

myWebView.getSettings().setUserAgentString("Android");
like image 95
Luis Avatar answered Oct 20 '22 00:10

Luis


As 2019 for Android devices have a look to: https://developer.chrome.com/multidevice/user-agent

So as documentation says:

WebView UA in Lollipop and Above

In the newer versions of WebView, you can differentiate the WebView by looking for the wv field as show in bold below.

Mozilla/5.0 (Linux; Android 5.1.1; Nexus 5 Build/LMY48B; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/43.0.2357.65 Mobile Safari/537.36

like image 33
soni Avatar answered Oct 20 '22 00:10

soni