Java reads Apk's package name, version number, permission list, minimum supported system version and other information

Java reads Apk's package name, version number, permission list, minimum supported system version and other information. Whether it is doing background development, or android development. Sometimes it is necessary to obtain information such as the version number, package name, permissions, and minimum supported system version of the apk file. For example, when doing an apk update, if it is not publishing an application store, when doing the update yourself. We may need to get basic information such as the apk version number of the server version.
So how to get the basic information of the apk file. Here is the file of a tool GetAPKInfo.jar. Using this jar package can help us get the basic information of apk.
Take the installation package of QQ as an example.

  • View package name, version number, signature and other information: java -jar GetApkInfo.jar qq.apk

    apkInfo picture

    To view the package name, version number, signature, minimum supported system version (minSdkVersion), permission list and other information, you can use the GetMorePackageInfo.jar file.
    You can enter: java -jar GetMorePackageInfo.jar qq.apk
    apkInfoMore

    Jar package download: GetApkInfo.jar
    Jar package download: GetMoreApkInfo.jar (recommended to use this)

    Specific use, take QQ as an example: after adding the jar package to the project

package com.xice.apk;

import java.io.File;

import org.json.JSONObject;

import com.android.apksigner.ApkSignerTool;
import com.bihe0832.packageinfo.bean.ApkInfo;
import com.bihe0832.packageinfo.getSignature.GetSignature;
import com.bihe0832.packageinfo.utils.ApkUtil;

public class TestApk {
	
	public static void main(String[] args) {
		String path = "src\\com\\xice\\apk\\base.apk";
		ApkInfo apkinfo = new ApkInfo();
		//获取md5值和签名信息
		JSONObject jsonobject = new JSONObject(ApkSignerTool.verify(path));
		apkinfo.isV1SignatureOK = jsonobject.optBoolean("isV1OK");
		apkinfo.isV2Signature = jsonobject.optBoolean("isV2");
		apkinfo.isV2SignatureOK = jsonobject.optBoolean("isV2OK");
		apkinfo.signature = jsonobject.optString("keystoreMd5");
		apkinfo.v2CheckErrorInfo = jsonobject.optString("msg");
		//获取apk其他基本信息
		ApkUtil.getApkInfo(path, apkinfo);
		System.out.println(apkinfo.toString());
	}

}

Screenshot of the result display:
Results screenshot

You can get the package name, version name, version number, signature file md5 value, minimum SDK version, minimum system version supported by the application, signature status of v1 and v2, and a list of permissions required by the current application.
The above is to read apk version number, package name, v1 and v2 signature information, minimum supported system version and other information through java. If you have any questions, you can leave a message below.

Guess you like

Origin blog.csdn.net/xu_coding/article/details/84038190