views:

28

answers:

1

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.

A: 

If you don't have one you can try taking it like this

String ua=new WebView(this).getSettings().getUserAgentString();

Edit-

The doc for getUserAgentString() says

Return the WebView's user-agent string.

So i don't think you can get it unless you declare one. Some one correct me if i am wrong

Rahul
Thanks, it works. Would be nice to get around it without creating an object, but seems it is not really possible...
Laimoncijus