jeudi 22 septembre 2016

how can i call Android hide Handler(boolean b) constructor?

android.os.Handler class has a hide constructor --> void Handler(boolean async),

I just want to call this method by reflection,but in vain...

here is my code:

    Class clazz = Class.forName("android.os.Handler");
    Constructor construct = clazz.getConstructor(boolean.class);
    //Constructor construct = clazz.getDeclaredConstructor(boolean.class);
    construct.setAccessible(true);

    boolean[] ailments = new boolean[]{true};
    Handler handler = (Handler) construct.newInstance(ailments);

the error message is:

java.lang.NoSuchMethodException: android.os.Handler.<init>(boolean)

at java.lang.Class.getConstructor0(Class.java:3082)
at java.lang.Class.getConstructor(Class.java:1825)....

I try to iterate the clazz.getConstructors() returns Constructor array, and log their ParamsType, just find Looper,Callback ...

why it can't log out 'boolean'?

public More ...Handler(boolean async) {
    this(null, async);
}





Aucun commentaire:

Enregistrer un commentaire