2

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 ?

General Grievance
  • 4,555
  • 31
  • 31
  • 45

1 Answers1

3

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);
Vladyslav Matviienko
  • 10,610
  • 4
  • 33
  • 52