简体   繁体   中英

How to get appicon programmatically from sdcard/storage .apk file?

Using ApplicationInfo i'm already tried and it works well but it is shows only installed app's appicon. but i want to get appicon from file path(.apk file) programmatically.

Drawable icon=applicationInfo.loadIcon(getPackageManager());

I want to get appicon from apk file. this file is already stored in storage.

so is there a way to get icon/thumb from .apk file for showing appicon programmatically ?

You can get that info from APK file:

 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM