Java tutorial
//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); userAgent = settings.getUserAgentString(); } finally { constructor.setAccessible(false); } } catch (Exception e) { userAgent = new WebView(context).getSettings().getUserAgentString(); } } return userAgent; } }