package com.hysj.utils;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import net.dongliu.apk.parser.ApkFile;
import net.dongliu.apk.parser.bean.ApkMeta;
import net.dongliu.apk.parser.bean.Permission;
import net.dongliu.apk.parser.bean.UseFeature;
{class ApkUtil public
/ **
* Get information APK
* @param apkUrl apk path
* @return information set (Map)
* /
public static Map <String, Object> readApk (String apkUrl) {
// create a collection, storage information APK
Map <String, Object> = new new ResMap the HashMap <String, Object> ();
// APK file acquiring
the try (ApkFile apkFile new new ApkFile = (new new file (apkUrl))) {
ApkMeta apkMeta apkFile.getApkMeta = (); // Get metadata APK file
/ ********************************************************** add content collection ************** *********** /
resMap.put ( "apkName", apkMeta.getName ()); // name APK
resMap.put ( "apkPackageName", apkMeta.getPackageName ( )); // apk package name
resMap.put("versionCode", apkMeta.getVersionCode()); //版本号
resMap.put("versionName", apkMeta.getVersionName()); //版本名称
} catch (IOException e) {
e.printStackTrace();
}
return resMap;
}
/ **
* main method of testing
* @param Arg
* /
public static void main (String [] Arg) {
String filePath = "E: \\ tencent.apk";
the try (ApkFile apkFile new new ApkFile = (new new File ( filePath))) {// Get APK file
ApkMeta apkMeta = apkFile.getApkMeta (); // get metadata file APK
System.out.println (apkMeta.getName ()); // apk name
System.out.println (apkMeta.getPackageName ()); // apk package name
System.out.println (apkMeta.getVersionCode ()); // version number
System.out.println (apkMeta.getVersionName ()); // release the name of
// required hardware or software resources / functions
for (UseFeature feature: apkMeta.getUsesFeatures () ) {
System.out.println(feature.getName());
}
for (Permission permission : apkMeta.getPermissions()) {
System.out.println(permission.getName());
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Operating results map
The required shelf package download path:
Link: https: //pan.baidu.com/s/1IlKlnaZSIHN5c-nkVNpTjg
extraction code: 6813