There is a java.lang.ClassCastException
when I am trying to get a installed applications icon.
Here is my code.
public Bitmap getAppIcon(String path) {
PackageInfo pi = pm.getPackageArchiveInfo(path, 0);
pi.applicationInfo.sourceDir = path;
pi.applicationInfo.publicSourceDir = path;
Drawable icon = pi.applicationInfo.loadIcon(pm);
Bitmap APKicon = ((BitmapDrawable) icon).getBitmap();
return APKicon;
}
where, pm
is
PackageManager pm = getPackageManager();
and the error shown in the LogCat
is
Caused by: java.lang.ClassCastException: android.graphics.drawable.NinePatchDrawable cannot be cast to android.graphics.drawable.BitmapDrawable
Hope anybody can help me.