diff --git a/GetAPKInfo.jar b/GetAPKInfo.jar index a6b37d2..1072b95 100644 Binary files a/GetAPKInfo.jar and b/GetAPKInfo.jar differ diff --git a/GetApkInfo/build.gradle b/GetApkInfo/build.gradle index 3a1a04b..9de072b 100644 --- a/GetApkInfo/build.gradle +++ b/GetApkInfo/build.gradle @@ -4,7 +4,7 @@ jar{ //项目名,也是生成的jar的名字 baseName = "GetAPKInfo" //项目版本号,这部分内容会写进manifest - version = "1.0" + version = "2.0.2" //项目的manifest定义,其中就包含最关键的入口类定义 manifest { attributes 'Main-Class': 'com.bihe0832.packageinfo.Main' diff --git a/GetApkInfo/src/main/java/com/bihe0832/packageinfo/Main.java b/GetApkInfo/src/main/java/com/bihe0832/packageinfo/Main.java index 373a91e..a033c70 100644 --- a/GetApkInfo/src/main/java/com/bihe0832/packageinfo/Main.java +++ b/GetApkInfo/src/main/java/com/bihe0832/packageinfo/Main.java @@ -15,8 +15,8 @@ public class Main { - private static final int VERSION_CODE = 7; - private static final String VERSION_NAME = "2.0.1"; + private static final int VERSION_CODE = 8; + private static final String VERSION_NAME = "2.0.2"; private static final String HELP_PAGE_GENERAL = "help.txt"; private static final String VERSION_PAGE_GENERAL = "help_version.txt"; private static boolean sShowDebug = true; @@ -52,7 +52,7 @@ public static void main(String[] params) throws Exception { private static void getApkInfo(String filePath){ ApkInfo info = new ApkInfo(); try { - ApkUtil.getApkInfo(filePath, info, sShowDebug); + ApkUtil.updateAPKInfo(filePath, info, sShowDebug); } catch(Exception e){ showFailedCheckResult(RET_GET_INFO_BAD,"get apkinfo failed, throw an Exception ;please use --debug get more info"); return; diff --git a/GetApkInfo/src/main/java/com/bihe0832/packageinfo/utils/ApkUtil.java b/GetApkInfo/src/main/java/com/bihe0832/packageinfo/utils/ApkUtil.java index c36ee6f..46a262d 100644 --- a/GetApkInfo/src/main/java/com/bihe0832/packageinfo/utils/ApkUtil.java +++ b/GetApkInfo/src/main/java/com/bihe0832/packageinfo/utils/ApkUtil.java @@ -1,57 +1,63 @@ package com.bihe0832.packageinfo.utils; +import com.bihe0832.packageinfo.bean.ApkInfo; import java.io.ByteArrayInputStream; +import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; - - +import java.util.Iterator; +import java.util.List; import org.jdom.Document; import org.jdom.Element; import org.jdom.Namespace; import org.jdom.input.SAXBuilder; -import com.bihe0832.packageinfo.bean.ApkInfo; - -import java.util.Iterator; -import java.util.List; - public class ApkUtil { - - private static final Namespace NS = Namespace.getNamespace("http://schemas.android.com/apk/res/android"); - - public static void getApkInfo(String apkPath, ApkInfo info, boolean showException){ - SAXBuilder builder = new SAXBuilder(); - Document document = null; - try{ - InputStream stream = new ByteArrayInputStream(AXMLPrinter.getManifestXMLFromAPK(apkPath).getBytes(StandardCharsets.UTF_8)); - document = builder.build(stream); - }catch (Exception e) { - if(showException){ - e.printStackTrace(); - } - } - Element root = document.getRootElement(); - info.versionCode = root.getAttributeValue("versionCode",NS); - info.versionName = root.getAttributeValue("versionName", NS); - String s = root.getAttributes().toString(); - String c[] = s.split(","); - for(String a: c){ - if(a.contains("package")){ - info.packageName = a.substring(a.indexOf("package=\"")+9, a.lastIndexOf("\"")); - } - } - - List booklist=root.getChildren("uses-sdk"); - Element book = (Element) booklist.get(0); - info.minSdkVersion = book.getAttributeValue("minSdkVersion", NS); - info.targetSdkVersion = book.getAttributeValue("targetSdkVersion", NS); - - booklist=root.getChildren("uses-permission"); - for (Iterator iter = booklist.iterator(); iter.hasNext();) { - Element tempBook = (Element) iter.next(); - info.permissions.add(tempBook.getAttributeValue("name", NS)); - } - } + private static final Namespace NS = Namespace.getNamespace("http://schemas.android.com/apk/res/android"); + + public static void updateAPKInfo(String apkPath, ApkInfo info, boolean showException) { + SAXBuilder builder = new SAXBuilder(); + Document document = null; + InputStream stream = null; + try { + stream = new ByteArrayInputStream( + AXMLPrinter.getManifestXMLFromAPK(apkPath).getBytes(StandardCharsets.UTF_8)); + document = builder.build(stream); + Element root = document.getRootElement(); + info.versionCode = root.getAttributeValue("versionCode", NS); + info.versionName = root.getAttributeValue("versionName", NS); + String s = root.getAttributes().toString(); + String c[] = s.split(","); + for (String a : c) { + if (a.contains("package")) { + info.packageName = a.substring(a.indexOf("package=\"") + 9, a.lastIndexOf("\"")); + } + } + + List booklist = root.getChildren("uses-sdk"); + Element book = (Element) booklist.get(0); + info.minSdkVersion = book.getAttributeValue("minSdkVersion", NS); + info.targetSdkVersion = book.getAttributeValue("targetSdkVersion", NS); + + booklist = root.getChildren("uses-permission"); + for (Iterator iter = booklist.iterator(); iter.hasNext(); ) { + Element tempBook = (Element) iter.next(); + info.permissions.add(tempBook.getAttributeValue("name", NS)); + } + } catch (Exception e) { + if (showException) { + e.printStackTrace(); + } + } finally { + if (null != stream) { + try { + stream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } } diff --git a/GetMoreAPKInfo.jar b/GetMoreAPKInfo.jar index 4fc7884..4fa87d8 100644 Binary files a/GetMoreAPKInfo.jar and b/GetMoreAPKInfo.jar differ