user577732
user577732

Reputation: 4056

Get icon of application on sdcard

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

Upvotes: 2

Views: 2429

Answers (1)

Binoy Babu
Binoy Babu

Reputation: 17139

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

Upvotes: 4

Related Questions