get User Agent String By Reflection - Android Network

Android examples for Network:User Agent

Description

get User Agent String By Reflection

Demo Code


import java.lang.reflect.Constructor;

import android.content.Context;

public class Main {
  private static String getUserAgentStringByReflection(Context context,
      String webSettingsClassName, String webViewClassName) throws Exception {
    boolean z = false;
    Class<?> webSettingsClass = Class.forName(webSettingsClassName);
    Constructor<?> constructor = webSettingsClass
        .getDeclaredConstructor(new Class[] { Context.class,
            Class.forName(webViewClassName) });
    constructor.setAccessible(true);//  ww w  .java2 s.  c o m
    String str = (String) webSettingsClass.getMethod("getUserAgentString",
        Boolean.class).invoke(
        constructor.newInstance(new Object[] { context, null }), new Object[0]);
    constructor.setAccessible(z);
    return str;
  }
}

Related Tutorials