Skip to content

Instantly share code, notes, and snippets.

@metalwihen
Created March 14, 2018 04:52
Show Gist options
  • Save metalwihen/bb5c743e134e3ec6d4f1d66160024038 to your computer and use it in GitHub Desktop.
Save metalwihen/bb5c743e134e3ec6d4f1d66160024038 to your computer and use it in GitHub Desktop.
UserAgent
    private String getUserAgent() {
        if (mUserAgentString == null) {
            String productWithVersion = String.format("%s/%s", BuildConfig.APPLICATION_ID, BuildConfig.VERSION_CODE);
            String androidUserAgent = System.getProperty("http.agent");
            if (androidUserAgent == null && productWithVersion != null) {
                mUserAgentString = productWithVersion; // in case null is returned
            } else if (productWithVersion != null) {
                mUserAgentString = String.format("%s %s", productWithVersion, androidUserAgent);
            } else {
                mUserAgentString = "undefined???";
            }
        }

        return mUserAgentString;  
    }
com.kayako.android.k5/204 Dalvik/2.1.0 (Linux; U; Android 7.0; Android SDK built for x86_64 Build/NYC)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment