/** * 擷取APK的基本資料 * @param apkPath * @return * @throws java.io.IOException */ String osName = System.getProperty("os.name").toUpperCase(); String appName = osName.indexOf("LINUX")!=-1?"aapt/aapt":"aapt/aapt.exe"; Map<String,String> map = new HashMap<String, String>(); String command = Thread.currentThread().getContextClassLoader().getResource(appName).getFile()+" dump badging d://xxx.apk"; Process process= Runtime.getRuntime().exec(command); BufferedReader reader= new BufferedReader(new InputStreamReader(process.getInputStream(),"UTF-8")); String line; StringBuilder result = new StringBuilder(100); while ((line=reader.readLine())!=null){ result.append(line+"\n"); } System.out.println(result.toString()+"\n\n"); String reg = "\\s(.+?)[=|:]'(.*?)'"; Matcher matcher = Pattern.compile(reg).matcher(result.toString()); while (matcher.find()){ System.out.println(matcher.group(1)+" "+matcher.group(2)); String key = matcher.group(1); if(map.get(key) == null){ map.put(key,matcher.group(2)); } }
aapt下載地址