[uiautomator篇] 如何获取apk的包名 博客模板
----------------------------------------------------------------------------------------------------------------------------
小记:自学过程中,经常需要用得到一个APK的包名,总结一下得到包名的几种方式。
**********************
2017-16-23:初版
**********************
------------------------------------------------------------------------------------------------------------------------------
我们主要用的是adb shell命令
方法1. 通过adb shell进入到手机data/data目录下,查看包名(需要root)
adb shell cd data/data ls
方法2. 通过adb shell的pm命令,查看包名(不需要root)
adb shell pm list package -f
还可以加上过滤信息
adb shell pm list package -f |findstr antutu
方法3. 代码形式获取:
package com.example.apppackages; import android.graphics.drawable.Drawable; public class AppPackageInfo { public String appName=""; public String packageName=""; public String versionName=""; public int versionCode=0; public Drawable appIcon=null; }
- ArrayList<AppPackageInfo> appList = new ArrayList<AppPackageInfo>();
- List<PackageInfo> packages = getPackageManager().getInstalledPackages(0);
- for(int i=0;i<packages.size();i++) {
- PackageInfo packageInfo = packages.get(i);
- AppPackageInfo tmpInfo = new AppPackageInfo();
- tmpInfo.appName = packageInfo.applicationInfo.loadLabel(getPackageManager()).toString();
- tmpInfo.packageName = packageInfo.packageName;
- tmpInfo.versionName = packageInfo.versionName;
- tmpInfo.versionCode = packageInfo.versionCode;
- tmpInfo.appIcon = packageInfo.applicationInfo.loadIcon(getPackageManager());
- appList.add(tmpInfo);
- Log.i("tag", tmpInfo.packageName);
- }
4 使用android/sdk 在SDK的build-tools目录下. 该工具可以查看, 创建, 更新ZIP格式的文档附件(zip, jar, apk)
aapt dump badging (apk path)|findstr package
C:\Users\Administrator\AppData\Local\Android\Sdk\build-tools\25.0.3>aapt dump badging E:\uitest\testcase\CaseDemo\testcase\antutu\Antutu3D.apk | findstr package
package: name='com.antutu.benchmark.full' versionCode='6000302' versionName='6.0
.3' platformBuildVersionName='6.0-2438415'