10

システム上のすべてのアプリのリストを取得する次のコードがあります。

    PackageManager pm = getPackageManager();

    Intent mainIntent = new Intent(Intent.ACTION_MAIN);

    List<ResolveInfo> installedApps = pm.queryIntentActivities( mainIntent, 0);

    for(ResolveInfo elem : installedApps) {
            String PackageName = elem.activityInfo.applicationInfo.packageName;
            Log.i("TAG",PackageName);
    }

しかし、installedApps の結果には、多数の PackageName が繰り返されています。これは可能ですか?インテントの「失敗」が原因ですか、それとも多くのアプリのパッケージ名が同じ名前を持っているためですか?

4

5 に答える 5

14

これは可能ですか?

もちろん。

意図の「失敗」だから

いいえ、少なくとも「失敗」の私の定義ではありません。

または、多くのアプリの packageNames が同じ名前を持っているためですか?

いいえ。

これは、アプリケーションではなくアクティビティを照会しているためです。アプリケーションには、.ACTION_MAIN Intent

于 2013-06-21T15:28:13.600 に答える
7

いいえ、すべてのアプリには一意のパッケージ名が必要です。インストール済みの別のアプリで既に使用されているパッケージ名でアプリをインストールすると、それが置き換えられます。

したがって、他の理由があるはずです。1 つの推測はqueryIntentActivities、特定のインテントに対して実行できるすべてのアクティビティを取得することです。そのため、同じパッケージ名でアクティビティ情報を返すことができます。

getInstalledApplicationsメソッドを使用して試すことができます。デバイスにインストールされているすべてのアプリケーション パッケージのリストを返します。

于 2013-06-21T15:28:48.657 に答える
6

すべてのアプリケーションには、一意のパッケージ名が必要です。API ガイドから引用すると、 「パッケージ名はアプリケーションの一意の識別子として機能します」および「アプリケーションを公開したら、パッケージ名を変更することはできません。パッケージ名はアプリケーションの ID を定義するため、変更すると、別のアプリケーションと見なされ、以前のバージョンのユーザーは新しいバージョンに更新できません。」

単一のマニフェストに複数の ACTION_MAIN エントリを含めることは、アプリケーションへの代替エントリ ポイントを表すため、完全に有効であることに注意してください。詳細については、この質問を参照してください。

于 2013-06-21T15:29:59.573 に答える
0

NO,

Caution: Once you publish your application, you cannot change the package name. The package name defines your application's identity, so if you change it, then it is considered to be a different application and users of the previous version cannot update to the new version.

Docs

But there are different entry points by using intent-filter in different different Activities.

 <intent-filter>
      <action android:name="android.intent.action.MAIN" />
      <category android:name="android.intent.category.LAUNCHER" />
 </intent-filter>

PACKAGE NAME: A full Java-language-style package name for the application. The name should be unique. The name may contain uppercase or lowercase letters ('A' through 'Z'), numbers, and underscores ('_'). However, individual package name parts may only start with letters. To avoid conflicts with other developers, you should use Internet domain ownership as the basis for your package names (in reverse). For example, applications published by Google start with com.google. You should also never use the com.example namespace when publishing your applications.

The package name serves as a unique identifier for the application. It's also the default name for the application process (see the <application> element's process process attribute) and the default task affinity of an activity (see the <activity> element's taskAffinity attribute).

于 2016-02-12T08:23:16.070 に答える