如何以编程方式从 sdcard/storage .apk 文件中获取应用程序图标?
How to get appicon programmatically from sdcard/storage .apk file?
使用 ApplicationInfo
我已经尝试过了,效果很好,但它只显示已安装应用程序的应用程序图标。但我想以编程方式从文件路径(.apk 文件)获取 appicon。
Drawable icon=applicationInfo.loadIcon(getPackageManager());
我想从 apk 文件中获取应用图标。此文件已存储在存储器中。
那么有没有办法从 .apk 文件中获取 icon/thumb 以编程方式显示应用图标?
您可以从 APK 文件中获取该信息:
String apkPath = "path/to/apk/file.apk";
PackageManager packageManager = context.getPackageManager();
PackageInfo packageInfo = packageManager.getPackageArchiveInfo(apkPath, 0);
// you need to set this variables manually for some reason to get icon from APK file that has not been installed
packageInfo.applicationInfo.sourceDir = apkPath;
packageInfo.applicationInfo.publicSourceDir = apkPath;
Drawable icon = packageInfo.applicationInfo.loadIcon(packageManager);
使用 ApplicationInfo
我已经尝试过了,效果很好,但它只显示已安装应用程序的应用程序图标。但我想以编程方式从文件路径(.apk 文件)获取 appicon。
Drawable icon=applicationInfo.loadIcon(getPackageManager());
我想从 apk 文件中获取应用图标。此文件已存储在存储器中。
那么有没有办法从 .apk 文件中获取 icon/thumb 以编程方式显示应用图标?
您可以从 APK 文件中获取该信息:
String apkPath = "path/to/apk/file.apk";
PackageManager packageManager = context.getPackageManager();
PackageInfo packageInfo = packageManager.getPackageArchiveInfo(apkPath, 0);
// you need to set this variables manually for some reason to get icon from APK file that has not been installed
packageInfo.applicationInfo.sourceDir = apkPath;
packageInfo.applicationInfo.publicSourceDir = apkPath;
Drawable icon = packageInfo.applicationInfo.loadIcon(packageManager);