0

ResolveInfoApplicationInfo( を拡張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));
    }
4

1 に答える 1

1

ApplicationInfo ドキュメント:

特定のアプリケーションに関して取得できる情報。これは、AndroidManifest.xml のタグから収集された情報に対応します。

ResolveInfo ドキュメント:

IntentFilter に対するインテントの解決から返される情報。これは、AndroidManifest.xml のタグから収集された情報に部分的に対応しています。

上記から、Google Play Music はアプリケーションの名前であり、Play Music はインテントに応答するアプリケーション内のアクティビティの名前のようです。

于 2015-05-02T03:41:46.193 に答える