Android获取高清app图标只有一个方法,具体内容如下 public synchronized static Drawable getIconFromPackageNa
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);
}
您可能感兴趣的文章:Android实现底部图标与Fragment的联动实例Android开发之APP安装后在桌面上不显示应用图标的解决方法Android 桌面图标右上角显示未读消息数字Android实现下拉刷新的视图和图标的旋转Android如何动态改变App桌面图标Android输入框添加emoje表情图标的实现代码Android中正确使用字体图标(iconfont)的方法Android App更改应用的图标的实现方法
--结束END--
本文标题: Android获取高清app图标代码分享
本文链接: https://lsjlt.com/news/23759.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-01-21
2023-10-28
2023-10-28
2023-10-27
2023-10-27
2023-10-27
2023-10-27
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0