User agent android linux

Android HTTP User Agent

How do I get the real device in http_user_agent? When I use a WebView, I can get the real value like this:

[HTTP_USER_AGENT] => Mozilla/5.0(Linux; U; Android 2.2; en-gb; LG-P500 Build/FRF91) AppleWebKit/533.0 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 
[HTTP_USER_AGENT] => Apache-HttpClient/UNAVAILABLE(java 1.4). 

4 Answers 4

To complete the accepted answer, if you want the default user agent use System.getProperty(«http.agent»)

client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, System.getProperty("http.agent")); 

If you don’t want to call setHeader() for every request you create you can set the http client parameter CoreProtocolPNames.USER_AGENT . After doing this HTTP client will automatically add this header parameter to each request.

client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Custom user agent"); 

when you create your HttpClient .

If you want to set your own user agent header then you have to use the setHeader method.

In case of a HTTP Post request you just set it like this.

private String url = "http://myfancyurl.com/"; private String ua = "My Custom UA Header String"; private HttpPost post = new HttpPost(url); post.setHeader("User-Agent", ua); 

This was just a short explanation how to set a custom user agent string. Your code might look different. The important part is the setHeader method.

Источник

User agent android linux

Published on Friday, February 28, 2014 • Updated on Tuesday, November 9, 2021

With Privacy Sandbox, an origin trial is in progress for reduced User-Agent strings, designed to remove sensitive information which may be used for fingerprinting.

A browser’s User-Agent string (UA) helps identify which browser is being used, what version, and on which operating system. When feature detection APIs are not available, use the UA to customize behavior or content to specific browser versions.

Читайте также:  Linux find all java versions

Like all other browsers, Chrome for Android sends this information in the User-Agent HTTP header every time it makes a request to any site. It’s also available in the client through JavaScript using the navigator.userAgent call.

# Chrome for Android

Chrome for Android reports its UA in the following formats, depending on whether the device is a phone or a tablet.

Mozilla/5.0 (Linux; ; ) AppleWebKit/ (KHTML, like Gecko) Chrome/ Mobile Safari/
Mozilla/5.0 (Linux; ; ) AppleWebKit/ (KHTML, like Gecko) Chrome/ Safari/

Here’s an example of the Chrome user agent string on a Galaxy Nexus:

AppleWebKit/535.19 (KHTML, like Gecko) 
Chrome/18.0.1025.133 Mobile Safari/535.19

If you are parsing user agent strings using regular expressions, the following can be used to check against Chrome on Android phones and tablets:

  • Phone pattern: ‘Android’ + ‘Chrome/[.0-9]* Mobile’
  • Tablet pattern: ‘Android’ + ‘Chrome/[.0-9]* (?!Mobile)’

# Chrome for iOS

The UA in Chrome for iOS is the same as the Mobile Safari user agent, with CriOS/ instead of Version/ .

Here’s an example of the Chrome UA on iPhone:

Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1

For comparison, the Mobile Safari UA:

AppleWebKit/603.1.23 (KHTML, like Gecko)
Version/10.0 Mobile/14E5239e Safari/602.1

Up to Chrome 84, when the Request Desktop Site feature is enabled, the Desktop Safari UA is sent:

AppleWebKit/600.7.12 (KHTML, like Gecko)
Version/8.0.7 Safari/600.7.12

Starting from Chrome 85, when the Request Desktop Site feature is enabled, the UA is the same as the Desktop Safari UA with CriOS/ being added:

AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/85
Version/11.1.1 Safari/605.1.15

# WebView on Android

The Android 4.4 (KitKat) Chromium-based WebView adds Chrome/_version_ to the user agent string.

AppleWebKit/534.30 (KHTML, like Gecko)
Version/4.0 Safari/534.30

WebView UA in KitKat to Lollipop

Mozilla/5.0 (Linux; Android 4.4; Nexus 5 Build/_BuildID_) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36

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. Don’t rely on the specific Chrome version number (for example, 30.0.0.0) as the version numbers changes with each release.

Читайте также:  Автозапуск virtualbox linux debian

WebView UA in Lollipop to Android 10

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

WebView UA in Android 10 and above

In the newer versions of WebView, you can differentiate the WebView by looking for the wv field as highlighted in the following string.

Mozilla/5.0 (Linux; U; Android 10; SM-G960F Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/95.0.4638.50 Mobile Safari/537.36 OPR/60.0.2254.59405

With Privacy Sandbox, an origin trial is in progress for reduced User-Agent strings, designed to remove sensitive information which may be used for fingerprinting.

Updated on Tuesday, November 9, 2021 • Improve article

Источник

Оцените статью
Adblock
detector