[英]How do I Use Reflection API getParameters in Android API level 25 and Below?
I am currently building an in-app logger utility for Android that uses the Reflection API to log basic data about the called class/method/parameters. 我目前正在为Android构建一个应用程序内记录器实用程序,该实用程序使用Reflection API记录有关所调用的类/方法/参数的基本数据。
Method.getParameters()
is the call to retrieve an array of parameters for the given method, but this method only works on Android API level 26+ . Method.getParameters()
是为给定方法检索参数数组的调用, 但是此方法仅适用于Android API级别26+ 。 Does anyone know of a workaround that would let me use getParameters()
on API level 25 or below? 有谁知道可以让我在API级别25或以下使用
getParameters()
的变通方法吗?
Alternatively, if there is a decent workaround for this, that would work too! 另外,如果有一个不错的解决方法,那也行得通! Thanks in advance!
提前致谢! Here is the method I will be updating once I have a fix/workaround in place:
一旦有了适当的修复/解决方法,这就是我将更新的方法:
private Parameter[] _retrieveParametersForMethod( Method method ) {
Parameter[] methodParameters;
// getParameters() only works on API level 26+ (Oreo)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
return methodParameters = method.getParameters();
} else
return null; // TODO: Find a workaround for pre-API level 26
}
Not sure if it will work for you, but I got a lot of mileage out of apache beanutils: 不知道它是否对您有用,但是我从apache beanutils中学到了很多东西:
http://commons.apache.org/proper/commons-beanutils/ http://commons.apache.org/proper/commons-beanutils/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.