Android Context Get getUserAgentString(Context context)

Here you can find the source of getUserAgentString(Context context)

Description

get User Agent String

License

Open Source License

Declaration

public static String getUserAgentString(Context context) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import android.content.Context;

import android.webkit.WebSettings;
import android.webkit.WebView;

import java.lang.reflect.Constructor;

public class Main {
    private static String userAgent = null;

    public static String getUserAgentString(Context context) {
        if (userAgent == null) {
            try {
                Constructor<WebSettings> constructor = WebSettings.class
                        .getDeclaredConstructor(Context.class,
                                WebView.class);
                constructor.setAccessible(true);
                try {
                    WebSettings settings = constructor.newInstance(context,
                            null);/*  w ww . j  a  v a2 s  .co m*/
                    userAgent = settings.getUserAgentString();
                } finally {
                    constructor.setAccessible(false);
                }
            } catch (Exception e) {
                userAgent = new WebView(context).getSettings()
                        .getUserAgentString();
            }
        }
        return userAgent;
    }
}

Related

  1. getTCFont(Context context)
  2. getTCItalicFont(Context context)
  3. getTempFile(Context context)
  4. getTimestamp(Context context)
  5. getTypeface(Context context, String name)
  6. getVersion(Context context)
  7. getVersionCode(Context mContext)
  8. getVoiceSearchIMId(Context context)