android - 获取apk文件图标、版本、名称

标签 android

对于尚未安装的软件包,有没有办法获取应用程序名称、应用程序版本和应用程序图标? (对于 sdcard 上的一些 apk 文件)

最佳答案

我只是花了比我承认的更多的时间来寻找这个问题的解决方案......并找到了它! :) :)

进入这个引用后: http://code.google.com/p/android/issues/detail?id=9151 我发现了从尚未安装的 .apk 文件中获取图标和名称(即标签)的技巧。

我希望在这方面帮助其他人还为时不晚:

 String APKFilePath = "mnt/sdcard/myapkfile.apk"; //For example...
 PackageManager pm = getPackageManager();
 PackageInfo    pi = pm.getPackageArchiveInfo(APKFilePath, 0);

 // the secret are these two lines....
 pi.applicationInfo.sourceDir       = APKFilePath;
 pi.applicationInfo.publicSourceDir = APKFilePath;
 //

 Drawable APKicon = pi.applicationInfo.loadIcon(pm);
 String   AppName = (String)pi.applicationInfo.loadLabel(pm);

经过简单测试后,它似乎可以工作......哇。

关于android - 获取apk文件图标、版本、名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5661418/

相关文章:

android - 如何修复错误 Gradle DSL 方法未找到 : 'compile()' ?

Android:getArguments() 总是得到空值

android - 如何使用适用于 android 的 Windows 7 64 位操作系统使用 ndk r12 配置 FFmpeg 库

android - Android 错误跟踪器在哪里? (Android Google Code 项目除外)

android - 隐藏库源代码

Android 如何创建选项矩阵?

android - 将可绘制对象转换为字符串以传递给另一个 Activity

java - 尝试根据选择的单选按钮保存单选组的状态

android - 将 Kotlin 运行时库添加到 android 中的 aar

android - 无法使用 Google USB 驱动程序