Can two different applications have the same package name?

I have this code to get a list of all the applications in the 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 a lot of duplicate package names. Is it possible? Does this mean “abandoning” the intention or because many package application names have the same name?

+8
source share
5 answers

Is it possible?

Sure.

It means a “failure” of intent

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

or because many package names have the same name?

No.

This is because you are requesting actions, not applications. An application can have zero, one, two, or a million actions that will respond to an ACTION_MAIN Intent .

+11
source

No, each application must have a unique package name. If you install an application with a package name that is already in use in another installed application, it will replace it.

So there must be other reasons. One assumption is that queryIntentActivities retrieves all the actions that can be performed for a given intent. That way, it can return action information with the same package name.

You can try using the getInstalledApplications method. A list of all application packages installed on the device will be returned.

+6
source

Each application must have a uniqe package name. To quote the API manual : “The package name serves as a unique identifier for the application” and “After publishing your application, you cannot change the package name. The package name defines the identifier of your application, so if you change it, it is considered another application, and users of the previous version do not may upgrade to the new version. "

Note that having multiple ACTION_MAIN entries in the same manifest works fine, as they represent alternative entry points to the application. See this question for more details.

+5
source

The package name acts as a folder structure. In my opinion, this can be seen when you enter the data-> data folder on the device or emulator.

Do we need different folders for different applications?

I would say that it’s better to be like that. Since I do not want you to have the same name to redefine each other and make unexpected behavior or failures. If you are sure that both applications do not have collisions in class names or so, I believe that it was the same.

0
source

NO,

Note: after publishing the application, you cannot change the package name. The name of the package determines your identifier for your application, so if you change it, it is considered another application, and users of the previous version cannot upgrade to the new version.

Documentation

But there are different entry points using the intent filter in different actions.

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

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

The package name is a unique identifier for the application. It is also the default name for the application process (see the process attribute <application> element process ) and the default affinity of the task for the action (see the <activity> element taskAffinity ).

0
source

Source: https://habr.com/ru/post/947846/


All Articles