Use case of APKParser vs. getPackageManager().getPackageArchiveInfo()
dschuermann opened this issue · 3 comments
dschuermann commented
I was wondering what the advantages of are of this library in comparison to getPackageManager().getPackageArchiveInfo()
. Can you make a small comparison? Currently I am wondering why APKParser exist. What are the drawbacks of getPackageArchiveInfo
?
jaredrummler commented
You can't get the following info using PackageManager
:
- Dex classes
- Method count
- Field count
- Decoded XML
- Target/Max SDK version
Everything else should be available using getPackageManager().getPackageArchiveInfo()
. If you don't need any of the extra info/metadata that this library provides, then stick with using PackageManager
.
dschuermann commented
Awesome Thanks
eighthave commented
While its not using PackageManager
, I believe that this code works for getting targetSdkVersion
and maxSdkVersion
:
AssetManager am = context.createPackageContext(packageName, 0).getAssets();
XmlResourceParser xml = am.openXmlResourceParser("AndroidManifest.xml");
int eventType = xml.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG && "uses-sdk".equals(xml.getName())) {
for (int j = 0; j < xml.getAttributeCount(); j++) {
if (xml.getAttributeName(j).equals("minSdkVersion")) {
minSdkVersion = Integer.parseInt(xml.getAttributeValue(j));
} else if (xml.getAttributeName(j).equals("targetSdkVersion")) {
targetSdkVersion = Integer.parseInt(xml.getAttributeValue(j));
} else if (xml.getAttributeName(j).equals("maxSdkVersion")) {
maxSdkVersion = Integer.parseInt(xml.getAttributeValue(j));
}
}
break;
}
eventType = xml.nextToken();
}