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); }
相关推荐
任玉刚 2019-11-19
jianjianyuer 2013-12-30
herionliu 2019-06-26
CosetteQi 2016-12-12
jianjianyuer 2014-11-03
redbricks 2013-12-30
airgreen 2012-11-05
wangruoze 2012-09-20
redbricks 2012-08-07
lizaochengwen 2012-04-27
redbricks 2012-04-27
Bierante 2018-09-28
云豹科技 2014-08-26
xuegangic 2013-09-02
govkbn 2012-04-28
snjezana 2012-04-26
flycappuccino 2014-03-12
Pinapps 2018-03-09
设计奇葩说 2018-02-01