Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

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

thanks
Nohsib

like image 937
Nohsib Avatar asked Jul 26 '11 02:07

Nohsib


People also ask

How do I find my user agent on Android?

Use navigator. userAgent property to get the value of the user-agent header sent by the browser to the server. Check the index of 'android' in the userAgent.

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 the user agent of Android app?

The user-agent is the client application that sends a web request. This information is sent with the browser request and allows the server to send different content based on the client. For example, the user-agent helps you detect the type of web browser sending the request.

What is OkHttp userAgent?

OkHttp is a request protocol used by the Android network framework to process network requests.


1 Answers

as Varundroid mentioned in his answer,

String userAgent = System.getProperty("http.agent"); 

is better way to do it for Android 2.1 and above.

====================

From android source code.

public static String getDefaultUserAgent() {
    StringBuilder result = new StringBuilder(64);
    result.append("Dalvik/");
    result.append(System.getProperty("java.vm.version")); // such as 1.1.0
    result.append(" (Linux; U; Android ");

    String version = Build.VERSION.RELEASE; // "1.0" or "3.4b5"
    result.append(version.length() > 0 ? version : "1.0");

    // add the model for the release build
    if ("REL".equals(Build.VERSION.CODENAME)) {
        String model = Build.MODEL;
        if (model.length() > 0) {
            result.append("; ");
            result.append(model);
        }
    }
    String id = Build.ID; // "MASTER" or "M4-rc20"
    if (id.length() > 0) {
        result.append(" Build/");
        result.append(id);
    }
    result.append(")");
    return result.toString();
}   
like image 180
Prakash Nadar Avatar answered Oct 16 '22 12:10

Prakash Nadar