2

Hi I have an application on my sd (not installed just stored there) how can I get information about it by just giving the path to the application. For instance I have pandora.apk sitting in my downloads folder so the path is /sdcard/download/pandora.apk knowing that path how can i get the icon of it. Thanks for any help

I've tried this code but get a nullpointerexception

final PackageManager pm = context.getPackageManager();
PackageInfo packageInfo = pm.getPackageArchiveInfo("/sdcard/download/pandora.apk", 0);
Drawable icOn = packageInfo.applicationInfo.loadIcon(context.getPackageManager());
Christofer Eliasson
  • 32,939
  • 7
  • 74
  • 103
user577732
  • 3,956
  • 11
  • 55
  • 76

1 Answers1

4

Its already answered here. How to show icon of apk in my File manager

if (file.getPath().endsWith(".apk")) {
String filePath = file.getPath();
PackageInfo packageInfo = context.getPackageManager().getPackageArchiveInfo(filePath, PackageManager.GET_ACTIVITIES);
ApplicationInfo appInfo = packageInfo.applicationInfo;
if (Build.VERSION.SDK_INT >= 8) {
    appInfo.sourceDir = filePath;
    appInfo.publicSourceDir = filePath;
}
Drawable icon = appInfo.loadIcon(context.getPackageManager());
bmpIcon = ((BitmapDrawable) icon).getBitmap();
}
Community
  • 1
  • 1
Binoy Babu
  • 16,699
  • 17
  • 91
  • 134
  • thanks sorry about the duplicate i searched but couldn't find what i was looking for guess i just didn't search well :) – user577732 Dec 17 '11 at 21:08