Android HTTP User Agent

user430926 picture user430926 · Oct 11, 2010 · Viewed 68.6k times · Source

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

But when I use an Apache connection, the result is different:

[HTTP_USER_AGENT] => Apache-HttpClient/UNAVAILABLE(java 1.4).

What's the problem?

Answer

Maragues picture Maragues · Jan 25, 2013

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"));