标签:
背景:
每次要获取apk包的package和launchable-activity名称都需要运行doc命令,感觉好浪费感情,因为经常记不住常常的路径,但又不想把aapt设置为环境变量
我这个工具分几步的:
1、JAVA代码输出package和launchable-activity名称名称
2、把此JAVA封装成EXE,虽然我技能太浅,但我还是想尝试一下
3、这个EXE能够上人自己上传apk包,然后点击输出package和aunchable-activity按扭,就能出现相应的值
目前是第1步,也完善了几个自己以前没用过的API:
package pc.driver.util.com.cn; import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Base { //File dir 是在哪个盘执行,String command cmd的命令 public static void runCMD(String command,File dir){ InputStream is =null; Process process=null; try { process =Runtime.getRuntime().exec(command, null, dir);//执行doc命令 //后面的所有操作即是读取这个命令的输出结果 is = process.getInputStream();//获取执行CMD命令后的信息 BufferedReader reader =new BufferedReader(new InputStreamReader(is)); String line =null; StringBuffer sb =new StringBuffer(); while((line = reader.readLine())!=null){ sb.append(line); } //截取package字符串 Pattern p =Pattern.compile("package: name(.*?)versionCode"); Matcher m =p.matcher(sb); List<String> list=new ArrayList<String>(); while(m.find()){ list.add(m.group(1)); } for (String str : list) { System.out.println("package"+str); } //截取acvitity字符串,以launchable-activity: name开头, label结尾 获取中间字符串内容 Pattern p1 =Pattern.compile("launchable-activity: name(.*?) label"); Matcher m1 =p.matcher(sb); List<String> list1=new ArrayList<String>(); while(m1.find()){ list1.add(m1.group(1)); } for (String str1 : list) { System.out.println("activity"+str1); } } catch (IOException e) { e.printStackTrace(); } finally{ try { process.getOutputStream().close(); is.close(); } catch (IOException e) { e.printStackTrace(); } } } public static void main(String[] args) { File dir=new File("F:/"); String command="F:/adt-bundle-windows-x86_64-20140702/sdk/build-tools/android-4.4W/aapt dump badging E:/apk/Pcdriver-1.9.9.9.apk"; runCMD(command, dir); } }
JAVA获取apk包的package和launchable-activity名称(一)
标签:
原文地址:http://www.cnblogs.com/sincoolvip/p/5882817.html