ApkInfo apkInfo = newApkInfo();
File file= newFile(apkPath);
InputStream inputStream= null;long fileLength =file.length();
apkInfo.setName(file.getName());
apkInfo.setSize(fileLength);
List permission = new ArrayList<>();
AXmlResourceParser parser= newAXmlResourceParser();try{
ZipFile zipFile= newZipFile(file);
ZipEntry zipEntry= new ZipEntry("AndroidManifest.xml");
inputStream=zipFile.getInputStream(zipEntry);
parser.open(inputStream);while (true) {int type =parser.next();if (type == XmlPullParser.END_DOCUMENT) break;if (type ==XmlPullParser.START_TAG) {if ("manifest".equals(parser.getName())) {int attributeCount =parser.getAttributeCount();for (int i = 0; i < attributeCount; i++) {switch(parser.getAttributeName(i)) {case "versionCode":
apkInfo.setVersionCode(parser.getAttributeValueData(i) + "");case "versionName":
apkInfo.setVersionName(parser.getAttributeValue(i));case "package":
apkInfo.setApkPackage(parser.getAttributeValue(i));
}
}
}if ("uses-sdk".equals(parser.getName())) {int attributeCount =parser.getAttributeCount();for (int i = 0; i < attributeCount; i++) {if ("minSdkVersion".equals(parser.getAttributeName(i))) {
apkInfo.setMinSdkVersion(parser.getAttributeValueData(i) + "");
}
}
}if ("uses-permission".equals(parser.getName())) {int attributeCount =parser.getAttributeCount();for (int i = 0; i < attributeCount; i++) {if ("name".equals(parser.getAttributeName(i))) {
permission.add(parser.getAttributeValue(i));
}
}
}
}
}
}catch (XmlPullParserException |IOException e) {
}finally{try{
parser.close();
inputStream.close();
}catch(IOException e) {
}
}
apkInfo.setUses_permission(permission);