我正在编写一个命令行工具来按包名获取应用名称,并尝试以下方式。
PackageManager 提供了该功能,但我的工具不是APK,因此没有上下文。
命令 AAPT 可以解析apk中的应用名称,adb shell aapt dump badging /data/app/com.google.android.apps.inbox-1/base.apk
,但我的设备没有问题,我从here下载了一个,它抱怨&#34 ;错误:仅支持位置独立可执行文件(PIE)"。
有什么帮助?
答案 0 :(得分:1)
要获取App Name,请尝试此操作。它将提供应用程序名称,该名称在应用程序清单的标记中定义。
PackageManager packageManager = getApplicationContext().getPackageManager();
ApplicationInfo applicationInfo ;
try {
applicationInfo = packageManager.getApplicationInfo( this.getPackageName(), 0);
} catch (final NameNotFoundException e) {
applicationInfo = null;
}
String applicationName = (String) (applicationInfo != null ? packageManager.getApplicationLabel(applicationInfo ) : "(unknown)");
答案 1 :(得分:0)
You can use AAPT2 command in linux to get the package name of an APK.
./aapt2 dump packagename <path_to_apk>
But you need to download newer versions of AAPT2 from here: Download AAPT from Google Maven
You can try this executing this command in a shell script, so that you will be able to use the package name.
PS: I used AAPT2 version 3.3.0-5013011 for testing the above command.