lundi 6 mai 2019

getDeclaredField can't get all field of the class( exclude the class) Toast.TN

when I hand the Toast BadTokenException with reflection in my android app ,but in the devices HUAWEI honor 10(android 9.0 Emui 9.0.0) and devices one plus 5T(android 9.0 H2OS 9.0.2) run this code above can not get Toast.TN class field, and I get the Exception msg "No field mHandler in class Landroid/widget/Toast$TN; (declaration of 'android.widget.Toast$TN' appears in /system/framework/framework.jar!classes2.dex)"

    private static Field sField_TN_Handler;
    static {
        try {
            sField_TN = Toast.class.getDeclaredField("mTN");
            sField_TN.setAccessible(true);
           sField_TN_Handler=sField_TN.getType().getDeclaredField("mHandler");
            sField_TN_Handler.setAccessible(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

where is problem with getDeclaredField(String field) method, getDeclaredField can't get all fields of the Toast.TN in android ?could someone help me?





Aucun commentaire:

Enregistrer un commentaire