java使用apk-parser解析apk,获取manifest中的版本号及自定义变量

apk-parser地址:
https://github.com/hsiafan/apk-parser

1.获取版本号等信息:

try (ApkFile apkFile = new ApkFile(new File(filePath))) {
    ApkMeta apkMeta = apkFile.getApkMeta();
    System.out.println(apkMeta.getLabel());
    System.out.println(apkMeta.getPackageName());
    System.out.println(apkMeta.getVersionCode());
    for (UseFeature feature : apkMeta.getUsesFeatures()) {
        System.out.println(feature.getName());
    }
}

2.若获取application节点下的自定义变量 TING_CHANNEL的值
在这里插入图片描述

我这里为了简单,使用正则匹配出TING_CHANNEL,示例代码如下:

String manifestXml = apkFile.getManifestXml();
System.out.println(manifestXml);
String text = MacherUtil.matcher("<meta-data android:name=\"TING_CHANNEL\" android:value=\".+\"", manifestXml);
text = MacherUtil.matcher("value=\".+\"", text).replaceFirst("value=\"", "").replaceAll("\"", "");
System.out.println(text);

打印:_91

完!

猜你喜欢

转载自blog.csdn.net/hechaojie_com/article/details/83585399