各アプリの高解像度アイコンが必要なアプリをやっています。
私は今朝からいくつかの調査を行いましたが、私が見つけた答えはどれもうまくいきませんでした.
ここにそれらのうちの2つがありますが、私にとって何が悪いのですか。
参考までに、パッケージマネージャーからすべての「packageinfo」を取得しました。必要なものはすべて見つかりましたが、高解像度のアイコンは...
1. getDrawableForDensity を使用:
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;
}
}
これに関する私の問題は、componentName に何を入力すればよいかわからないことです。packagemanager から取得した情報を使用して「構築」するにはどうすればよいですか?
2.その他の解決 方法 packageManager から xhdpi アプリのアイコンを取得していますか?
// 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);
「アイコン」に関するエラー:
アイコンを解決できないか、フィールドではありません