位置:首页 » 文章/教程分享 » java从apk文件里获取包名版本号

测试代码:

package org.apkinfo.test;  
  
import java.io.IOException;  
import java.util.ArrayList;  
  
import org.apkinfo.api.GetApkInfo;  
import org.apkinfo.api.domain.ApkInfo;  
  
public class GetApkInfoTest {  
    public static void main(String[] args) {  
        try {  
            ArrayList<ApkInfo> listAPKInfo = GetApkInfo.listApkInfoByDir("D:\\DefaultApkTempSaveFolder\\3D风景动态壁纸\\");  
            System.out.println(listAPKInfo);  
              
            ApkInfo apkInfo = GetApkInfo.getApkInfoByFilePath("D:\\DefaultApkTempSaveFolder\\3G安卓市场\\com.jiubang.market.apk");  
            System.out.println(apkInfo);  
        } catch (IOException e) {  
            e.printStackTrace();  
        }  
    }  
} 

运行结果:

[ApkInfo [packageName=cn.bighead.livewallpaper.fengjing3D123, versionName=1.4.7, versionCode=147]]
ApkInfo [packageName=com.jiubang.market, versionName=3.2.6, versionCode=35]