Android获取高清app图标代码分享
程序员文章站
2024-03-04 19:13:18
android获取高清app图标只有一个方法,具体内容如下
public synchronized static drawable geticonfrompa...
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); }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
上一篇: ASP.NET性能优化八条建议