我在做一個需要每個應用程序的高分辨率圖標的應用程序。如何使用PacakageManager找到高分辨率圖標
自從今天上午我做了一些研究,但沒有找到工作的答案。
這裏有兩個,我有什麼不對。
ActivityInfo info = packageManager.getActivityInfo(componentName, PackageManager.GET_META_DATA);
Resources resources;
try {
resources = mPackageManager.getResourcesForApplication(
info.applicationInfo);
} catch (PackageManager.NameNotFoundException e) {
resources = null;
}
if (resources != null) {
int iconId = info.getIconResource();
if (iconId != 0) {
Drawable d;
try {
d = resources.getDrawableForDensity(iconId, DisplayMetrics.DENSITY_XHIGH);
} catch (Resources.NotFoundException e) {
d = null;
}
return d;
}
}
:
僅供參考,我已經檢索到所有從packagemanager 「packageinfo」,我
1.使用getDrawableForDensity找到我需要的一切,但高分辨率圖標...
我這個問題是我不明白爲componentName放什麼。我如何用我從packagemanager獲得的信息「構建」它?
2.其他溶液 Retrieving xhdpi app icons from packageManager?
// Get the application's resources
Resources res = mPackageManager.getResourcesForApplication(appInfo);
// Get a copy of the configuration, and set it to the desired resolution
Configuration config = res.getConfiguration();
Configuration originalConfig = new Configuration(config);
config.densityDpi = DisplayMetrics.DENSITY_XHIGH;
// Update the configuration with the desired resolution
DisplayMetrics dm = res.getDisplayMetrics();
res.updateConfiguration(config, dm);
// Grab the app icon
Drawable appIcon = res.getDrawable(appInfo.icon);
// Set our configuration back to what it was
res.updateConfiguration(originalConfig, dm);
爲這一個我有此線的一個問題:
繪製對象APPICON = res.getDrawable(appInfo.icon);
錯誤我得到「圖標」:
圖標不能得到解決或無法在現場
您的解決方案「2」化險爲夷我們。謝謝。 –