反射獲取其他apk中類的變數和方法
阿新 • • 發佈:2018-12-24
TestErrorInfo.printClass(this, "com.android.bluetooth.opp.Constants");
public static void printClass(Context cc, String clsName) { try { Context c = cc.createPackageContext("com.android.bluetooth", Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY); //載入這個類 Class clazz = c.getClassLoader().loadClass(clsName);android.util.Log.w(TestEnv.TAG, "method: " + clazz.getName()); Field[] ff = clazz.getDeclaredFields(); for (Field f : ff) { android.util.Log.w(TestEnv.TAG, "field: " + f.getName()); } } catch (Throwable e) { e.printStackTrace(); } }