Android获取高清app图标 Android获取高清app图标代码分享
灬布衣丶公爵丨 人气:0想了解Android获取高清app图标代码讲解的相关内容吗,灬布衣丶公爵丨在本文为您仔细讲解Android获取高清app图标的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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); }
加载全部内容