Has anyone ever used the hidden class PackageParser in Android source code with java reflection?
I can get this class and its method collectCertificates() in the reflection way, but I keep getting the NoSuchMethodException with its method generatePackageInfo().
I am wondering whether the following sentence causes that problem, since I am not so sure about the usage of int[].class:
partypesGeneratePackageInfo[1] = int[].class;
Here is my code:
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);
......
}
For what I can see, the declaration for
generatePackageInfois:So that’s 5 parameters:
PackageParser.Package.class, int[].class, int.class, long.class, long.class.Since this is not an exposed API, it could very well be that the number of parameters changes from version to version.