一卷旌收千骑虏,万全身出百重围。这篇文章主要讲述Android--获取高清的app图标相关的知识,希望能为你提供帮助。
【Android--获取高清的app图标】只有一个方法。
1 public synchronized static Drawable getIconFromPackageName(String packageName, Context context) { 2PackageManager pm = context.getPackageManager(); 3if (Build.VERSION.SDK_INT > = Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { 4try { 5PackageInfo pi = pm.getPackageInfo(packageName, 0); 6Context otherAppCtx = context.createPackageContext(packageName, Context.CONTEXT_IGNORE_SECURITY); 7int displayMetrics[] = {DisplayMetrics.DENSITY_XXXHIGH,DisplayMetrics.DENSITY_XXHIGH,DisplayMetrics.DENSITY_XHIGH, DisplayMetrics.DENSITY_HIGH, DisplayMetrics.DENSITY_TV}; 8for (int displayMetric : displayMetrics) { 9try { 10Drawable d = otherAppCtx.getResources().getDrawableForDensity(pi.applicationInfo.icon, displayMetric); 11if (d != null) { 12return d; 13} 14} catch (Resources.NotFoundException e) { 15continue; 16} 17} 18} catch (Exception e) { 19// Handle Error here 20} 21} 22ApplicationInfo appInfo = null; 23try { 24appInfo = pm.getApplicationInfo(packageName, 0); 25} catch (PackageManager.NameNotFoundException e) { 26return null; 27} 28return appInfo.loadIcon(pm); 29}
推荐阅读
- x86架构的android手机兼容性问题
- Android设置输入框和软键盘动态悬浮
- Android中Listview点击item不变颜色以及设置listselector 无效
- android aidl 进程间通信需要注意的地方(android.os.TransactionTooLargeException)
- Android 动态改变高度以及计算长度的EditText
- 让Android的WebView支持html里面的文件上传
- android 图像处理系列合集
- Android--双击退出程序
- Android Studio目录结构浅析