有没有人在带有java反射的Android源代码中使用隐藏类PackageParser?
我可以通过反射方式获取此类及其方法 collectCertificates() ,但我不断获取 NoSuchMethodException 及其方法generatePackageInfo()。
我想知道以下句子是否会导致该问题,因为我不太确定int[].class的用法:
partypesGeneratePackageInfo[1] = int[].class;
这是我的代码:
private PackageInfo parsePackage(String archiveFilePath, int flags)
throws Exception, Exception {
// get class:PackageParser
Class clsPackageParser = Class
.forName("android.content.pm.PackageParser");
......
// get method:collectCertificates
Class partypesCollectCertificates[] = new Class[2];
partypesCollectCertificates[0] = clsPackage;
partypesCollectCertificates[1] = int.class;
Method methCollectCertificates = clsPackageParser.getMethod(
"collectCertificates", partypesCollectCertificates);
// invoke method:collectCertificates
Object arglistMethCollectCertificates[] = new Object[2];
arglistMethCollectCertificates[0] = objPackage;
arglistMethCollectCertificates[1] = flags;
methCollectCertificates.invoke(objPackageParser,
arglistMethCollectCertificates);
// get method:generatePackageInfo
Class partypesGeneratePackageInfo[] = new Class[3];
partypesGeneratePackageInfo[0] = clsPackage;
partypesGeneratePackageInfo[1] = int[].class;
partypesGeneratePackageInfo[2] = int.class;
Method methGeneratePackageInfo = clsPackageParser.getMethod(
"generatePackageInfo", partypesGeneratePackageInfo);
......
}