Here you can find the source of getUserAgentString(Context context)
public static String getUserAgentString(Context context)
//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; } }