Example usage for java.lang Class getDeclaredMethod

List of usage examples for java.lang Class getDeclaredMethod

Introduction

In this page you can find the example usage for java.lang Class getDeclaredMethod.

Prototype

@CallerSensitive
public Method getDeclaredMethod(String name, Class<?>... parameterTypes)
        throws NoSuchMethodException, SecurityException 

Source Link

Document

Returns a Method object that reflects the specified declared method of the class or interface represented by this Class object.

Usage

From source file:Main.java

private static void addtoClassLoader(URL url) throws IOException, NoSuchMethodException, SecurityException,
        IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader();
    Class<URLClassLoader> sysclass = URLClassLoader.class;
    Method method = sysclass.getDeclaredMethod("addURL", parameters);
    method.setAccessible(true);/*from w  w w .ja v a  2 s .c o  m*/
    method.invoke(sysloader, new Object[] { url });
}

From source file:Main.java

public static void showInternalDebugLog() {
    try {/*from w  w  w.  ja  va  2s .  c  om*/
        Class<?> clz = Class.forName("com.avos.avoscloud.AVOSCloud");
        Method startMethod = clz.getDeclaredMethod("showInternalDebugLog", Boolean.TYPE);
        startMethod.setAccessible(true);
        startMethod.invoke(null, true);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static File getExternalDownload() {
    try {/*from ww  w .j a v  a2 s.c  o m*/
        Class<?> c = Class.forName("android.os.Environment");
        Method m = c.getDeclaredMethod("getExternalStoragePublicDirectory", String.class);
        String download = c.getDeclaredField("DIRECTORY_DOWNLOADS").get(null).toString();
        return (File) m.invoke(null, download);
    } catch (Exception e) {
        return new File(Environment.getExternalStorageDirectory(), "Download");
    }
}

From source file:Main.java

public static Class getDeclaredMethodClass(Class clazz, String methodName, Class... params) {
    do {//from  w  w w .java2  s  .c  o  m
        try {
            clazz.getDeclaredMethod(methodName, params);
            return clazz;
        } catch (NoSuchMethodException e) {
            clazz = clazz.getSuperclass();
            if (clazz == null) {
                return null;
            }
        }
    } while (true);
}

From source file:BrowserLaunch.java

public static void launch(String url) {
    try {/*ww  w  .  jav a2  s  .  c  o  m*/
        if (isMacos) {
            Class fileMgr = Class.forName("com.apple.eio.FileManager");
            Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] { String.class });

            openURL.invoke(null, new Object[] { url });
        } else if (isWindows)
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
        else {
            if (BROWSER == null)
                throw new Exception("Could not find web browser");
            else
                Runtime.getRuntime().exec(new String[] { BROWSER, url });
        }
    } catch (Exception e) {
        System.out.println(
                "Unable to detect/startup your browser... please go to " + url + " for futher instructions");
    }
}

From source file:Main.java

public static Method getDeclaredMethod(Class<?> clazz, String name, Class<?>... argTypes) {
    try {/*from  w w w .j  av  a 2  s . c om*/
        final Method method = clazz.getDeclaredMethod(name, argTypes);
        method.setAccessible(true);
        return method;
    } catch (final SecurityException e) {
        throw new RuntimeException(e);
    } catch (final NoSuchMethodException e) {
        return null;
    }
}

From source file:Main.java

static public boolean setPinConfig(Class btClass, BluetoothDevice btDevice, boolean config) throws Exception {

    Method removeBondMethod = btClass.getDeclaredMethod("setPairingConfirmation",
            new Class[] { boolean.class });
    Boolean returnValue = (Boolean) removeBondMethod.invoke(btDevice, new Object[] { config });
    return true;/*from  w ww.ja v  a2  s.  co m*/
}

From source file:Main.java

public static void setIconEnable(Menu menu, boolean enable) {
    try {//from   w  w  w. j a v a2s. c o m
        Class<?> clazz = Class.forName("com.android.internal.view.menu.MenuBuilder");
        Method m = clazz.getDeclaredMethod("setOptionalIconsVisible", boolean.class);
        m.setAccessible(true);
        m.invoke(menu, enable);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static boolean hasMethod(Class<?> klass, String methodName, Class<?>... paramTypes) {
    try {/* w w w  .  ja  v a  2  s .co  m*/
        klass.getDeclaredMethod(methodName, paramTypes);
        return true;
    } catch (NoSuchMethodException e) {
        return false;
    }
}

From source file:Main.java

public static boolean setPairingConfirmation(Class<?> btClass, BluetoothDevice device, boolean isConfirm)
        throws Exception {
    Method setPairingConfirmation = btClass.getDeclaredMethod("setPairingConfirmation", boolean.class);
    return (boolean) setPairingConfirmation.invoke(device, isConfirm);
}