Retrieve User-Agent programmatically

Viewed 44338

Is there a way to retrieve Browser's user-agent without having a WebView in activity?

I know it is possible to get it via WebView:

WebView view = (WebView) findViewById(R.id.someview);
String ua = view.getSettings().getUserAgentString() ;

But in my case I don't have/need a webview object and I don't want to create it just for retrieving user-agent string.

6 Answers

Since Android 2.1 you should use System.getProperty("http.agent");

You also dont need to create a WebView first AND , thats the advantage, you can use it inside a non-uithread.

greetings steve

Related