/**
* 执行某对象方法
*
* @param owner 对象
* @param methodName 方法名
* @return 方法返回值
* @throws Exception
*/
private Object invokeMethod(Object owner, String methodName, Object[] args) {
String res = null;
Method method;
try {
Class ownerClass = owner.getClass();
if (args == null) {
method = ownerClass.getDeclaredMethod(methodName);
method.setAccessible(true);
res = (String) method.invoke(owner);
} else {
Class[] argsClass = new Class[args.length];
for (int i = 0; i < args.length; i++) {
if(args[i]!=null) {
Log.e(TAG, "invokeMethod: i ="+i);
argsClass[i] = args[i].getClass();
}
}
method = ownerClass.getDeclaredMethod(methodName, argsClass);
method.setAccessible(true);
res = (String) method.invoke(owner, args);
}
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
Log.d("e", e.getMessage());
}
return res;
}