我正在开发一个用于 Android 的 API。我想使用反射来访问在 android 活动类中实现的注释。我需要从我的 API 中反映出来。有办法吗?
我正在尝试将上下文传递给 API,但我可以获得注释所在的活动类。
该注解称为动作,如下:
@Action(
name = "test",
description = "this is just a test",
inputs = {"no input"},
output = {"no output"},
controlURL = "/api/v1/"
) public void testAction (){
/*
* Implements here the Action!
*/
}
我用来反映它的方法:
private static void getAction() {
if (D) Log.d(TAG, "getAction");
Class classWithAction = AppContext.getClass();
Annotation[] aAnnotations = classWithAction.getDeclaredAnnotations();
for(Annotation a : aAnnotations)
Log.d(TAG, a.toString());
}