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?
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.
Open the Settings app. Scroll down, tap Utilities, and tap Parallel Apps. You'll see a list of apps that you can make copies of—not every app is supported. Find the app you want to clone, and turn its toggle to the On position.
You can't do this. Each Android application has a package name, which effectively defines the Java/Dalvik namespace that its classes occupy. You cannot have two packages of the same name installed because it would create overlapping namespaces, which is why it always replaces the old one when you install a new one.
1 Answer. Please understand that the app's package name must be globally unique in Google Play (not just unique within your enterprise or Google Play Developer account).
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
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With