SoFunction
Updated on 2025-03-01

Android get high-definition app icon code sharing

There is only one way to get high-definition app icons on Android, the specific content is as follows

public synchronized static Drawable getIconFromPackageName(String packageName, Context context) {
  PackageManager pm = ();
  if (.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
   try {
    PackageInfo pi = (packageName, 0);
    Context otherAppCtx = (packageName, Context.CONTEXT_IGNORE_SECURITY);
    int displayMetrics[] = {DisplayMetrics.DENSITY_XXXHIGH,DisplayMetrics.DENSITY_XXHIGH,DisplayMetrics.DENSITY_XHIGH, DisplayMetrics.DENSITY_HIGH, DisplayMetrics.DENSITY_TV};
    for (int displayMetric : displayMetrics) {
     try {
      Drawable d = ().getDrawableForDensity(, displayMetric);
      if (d != null) {
       return d;
      }
     } catch ( e) {
      continue;
     }
    }
   } catch (Exception e) {
    // Handle Error here
   }
  }
  ApplicationInfo appInfo = null;
  try {
   appInfo = (packageName, 0);
  } catch ( e) {
   return null;
  }
  return (pm);
 }

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.