Search code examples
androidappicon

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 ?


Solution

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