android 类型名,android 获取当前apk中所有的类名代码
import java.lang.reflect.Field;import java.util.Enumeration;import dalvik.system.DexFile;import dalvik.system.PathClassLoader;public class Scanner {private static Field dexField;static {try {dexField
import java.lang.reflect.Field;
import java.util.Enumeration;
import dalvik.system.DexFile;
import dalvik.system.PathClassLoader;
public class Scanner {
private static Field dexField;
static {
try {
dexField = PathClassLoader.class.getDeclaredField("mDexs");
dexField.setAccessible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void scan() {
try {
PathClassLoader classLoader = (PathClassLoader) Thread.currentThread().getContextClassLoader();
DexFile[] dexs = (DexFile[]) dexField.get(classLoader);
for (DexFile dex : dexs) {
Enumeration entries = dex.entries();
while (entries.hasMoreElements()) {
String entry = entries.nextElement();
Class> entryClass = dex.loadClass(entry, classLoader);
if (entryClass != null) {
IBizAnno annotation = entryClass.getAnnotation(IBizAnno.class);
if (annotation != null) {
System.out.println("name=" + annotation.name() + "; class=" + entryClass.getName());
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
更多推荐
所有评论(0)