Skip to content

Instantly share code, notes, and snippets.

@MikeAfc
Created October 10, 2014 02:07
Show Gist options
  • Save MikeAfc/e81f320d456ceba362ec to your computer and use it in GitHub Desktop.
Save MikeAfc/e81f320d456ceba362ec to your computer and use it in GitHub Desktop.
get bitmap icon from apk file
if (file.getPath().endsWith(".apk")) {
String filePath = file.getPath();
PackageInfo packageInfo = context.getPackageManager().getPackageArchiveInfo(filePath, PackageManager.GET_ACTIVITIES);
if(packageInfo != null) {
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();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment