Can two different apps have the same packageName?

荒凉一梦 提交于 2019-12-08 16:55:20

问题


I have this code to get a list of all apps on system:

    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);
    }

But the result in installedApps shows many repeated PackageNames. Is this possible? It's 'cause a "failure" of the intent or because many apps packageNames have the same name?


回答1:


Is this possible?

Sure.

It's 'cause a "failure" of the intent

No, at least not for my definition of "failure".

or because many apps packageNames have the same name?

No.

It is because you are querying for activities, not applications. An application can have zero, one, two, or a million activities that will respond to an ACTION_MAIN Intent.




回答2:


No, every app should have a unique package name. If you install an app with a package name which is already used in another installed app, then it will replace it.

So there should be other reasons. One guess is queryIntentActivities retrieves all activities that can be performed for the given intent. So it can returns activities info with the same package name.

You can try using getInstalledApplications method. It will return a List of all application packages that are installed on the device




回答3:


Every application must have a uniqe package name. To quote from the API guide: "The package name serves as a unique identifier for the application" and "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."

Note that having multiple ACTION_MAIN entries in a single manifest is perfectly valid as they represent alternative entry points into the application. See this question for more information.




回答4:


The package name acts like a folder structure. You can see it when you go in to data->data folder in the device or emulator, I believe.

Do we need different folders for different applications?

I would say its better to be so. Since I don't want you files which same name to override each other and make unexpected behaviors or crashes. If you are sure that both application don't have a clash in class names or so, I believe it came be same.




回答5:


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).



来源:https://stackoverflow.com/questions/17238839/can-two-different-apps-have-the-same-packagename

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!