1. 程式人生 > >android 反射 記錄

android 反射 記錄

private static String audioParse(byte[] msgData) {
    try {
       // Object o = BUtils.getObj(msgData);
Class<?> cls = Class.forName("localpb.richMsg.RichMsg$PicRec");
Object haha = cls.newInstance();
//if (cls.isInstance(o)) {
Method method = cls.getMethod("mergeFrom", byte[].class);
method.invoke(haha, 
msgData); Field f =cls.getDeclaredField("rawMsgUrl"); Object local = f.get(haha); f.setAccessible(true); android.util.Log.e(TAG, "type:"+f.getClass()+"22name:"+f.getName()+">>>"+f.getType() +"hh:"+f.get(haha)); Class<?> cls11 = Class.forName("com.tencent.mobileqq.pb.PBStringField"); Field ll = cls11.getDeclaredField("value"
); ll.setAccessible(true); String ls = (String) ll.get(local); android.util.Log.e(TAG,"************ly*****************"+ls); Field fields[]=f.getClass().getDeclaredFields();//獲得物件所有屬性 Field field=null; for (int i = 0; i < fields.length; i++) { field=fields[i]; field.setAccessible(true
);//修改訪問許可權 android.util.Log.e(TAG, "lt:"+field.getName()); //android.util.Log.e(TAG, "lt:"+field.get(f)); } Method mm[]=f.getClass().getDeclaredMethods(); Method m=null; for (int i = 0; i < mm.length; i++) { m=mm[i]; m.setAccessible(true);//修改訪問許可權 android.util.Log.e(TAG, "lt:"+m.getName()); Class<?>[] parameterTypes = m.getParameterTypes(); for (Class<?> clas : parameterTypes) { String parameterName = clas.getName(); System.out.println("引數名稱:" + parameterName); } android.util.Log.e(TAG,"*****************************"); } Class<? extends Field> ttt = f.getClass(); Method m1 = ttt.getDeclaredMethod("get", Object.class); m1.setAccessible(true); String llr = (String) m1.invoke(f,f); android.util.Log.e(TAG, "llr:"+llr); //return tmp; //} } catch (Throwable e) { ZNativeCall.e(e); } return null; }