Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android獲取高清app圖標代碼分享

Android獲取高清app圖標代碼分享

編輯:關於Android編程

Android獲取高清app圖標只有一個方法,具體內容如下

public synchronized static Drawable getIconFromPackageName(String packageName, Context context) {
  PackageManager pm = context.getPackageManager();
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
   try {
    PackageInfo pi = pm.getPackageInfo(packageName, 0);
    Context otherAppCtx = context.createPackageContext(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 = otherAppCtx.getResources().getDrawableForDensity(pi.applicationInfo.icon, displayMetric);
      if (d != null) {
       return d;
      }
     } catch (Resources.NotFoundException e) {
      continue;
     }
    }
   } catch (Exception e) {
    // Handle Error here
   }
  }
  ApplicationInfo appInfo = null;
  try {
   appInfo = pm.getApplicationInfo(packageName, 0);
  } catch (PackageManager.NameNotFoundException e) {
   return null;
  }
  return appInfo.loadIcon(pm);
 }

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持本站。

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved