Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve User-Agent programmatically

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.

like image 230
Laimoncijus Avatar asked Sep 02 '10 10:09

Laimoncijus


People also ask

How to get User-Agent in android programmatically?

agent, which can be used to retrieve the User-Agent string. String userAgent = System. getProperty("http. agent");

How do I change the User-Agent on my Android phone?

Switch to the “Advanced” tab in the top-right corner, then tap “User agent” at the top of the “Customize” sub-section. 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.

What is Javascript User-Agent?

Definition and Usage. The userAgent property returns the user-agent header sent by the browser to the server. The userAgent property is read-only. The value returned, contains information about the browser name, version and platform.


1 Answers

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

like image 138
DeRagan Avatar answered Sep 29 '22 01:09

DeRagan