ResolveInfo
とApplicationInfo
( を拡張PackageItemInfo
する) の両方のクラスには、 loadLabel
「このアイテムに関連付けられている現在のテキスト ラベル」へのメソッドがあります。次のコードを実行してみました。最初のブロックはインテント クエリで取得した Play ミュージック アプリに関連付けられたラベルを出力し、2 番目のブロックはパッケージ名を使用したクエリで取得したアプリに関連付けられたラベルを出力しました。1 つ目は「Play Music」と表示されますが、2 つ目は「Google Play Music」と表示されます。何が起きてる?
PackageManager pm = getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> activities = pm.queryIntentActivities(intent,
PackageManager.GET_META_DATA);
for (ResolveInfo activity : activities) {
// prints out "Play Music"
Log.d("butt", "" + activity.loadLabel(pm));
}
ApplicationInfo appInfo = null;
try {
appInfo = pm.getApplicationInfo("com.google.android.music", 0);
} catch (NameNotFoundException e) { }
if (appInfo != null) {
// prints out "Google Play Music"
Log.d("butt", "" + appInfo.loadLabel(pm));
}