how to get the default HTTP USER AGENT from the android device?

Viewed 26765

How to get the default HTTP USER AGENT and its default settings from the android device?

thanks
Nohsib

4 Answers

When you use web view to access the user-agent, make sure you run the

new WebView(this).getSettings().getUserAgentString();

on the UI thread.

If you want access the user agent on background thread. use

System.getProperty("http.agent")

To check whether a user-agent is valid or not use this https://deviceatlas.com/device-data/user-agent-tester

An alternative

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
    String userAgent = WebSettings.getDefaultUserAgent(context);
}
Related