3

I'm trying to get every launchable applications in my device using this method:

apps = new ArrayList<>();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> availableActivities = manager.queryIntentActivities(intent, 0);
for(ResolveInfo ri:availableActivities){
    AppDetail app = new AppDetail();
    app.label = ri.loadLabel(manager);
    app.name = ri.activityInfo.packageName;
    app.icon = ri.activityInfo.loadIcon(manager);
    apps.add(app);
}

I tried to print the label and package name of those application and found this:
Contacts com.sonyericsson.android.socialphonebook
Phone com.sonyericsson.android.socialphonebook
They have different app label yet the same package name. When I tried to open the apps, both of them open Contact app.
Is there any way to differentiate them? Or did I use a wrong method to get list of application?

Shalu T D
  • 3,921
  • 2
  • 26
  • 37
AhmadF
  • 143
  • 10
  • You can't have two applications with the same name installed. They would conflict when you attempted it, and installation of the second would fail, or overwrite the original. What you're seeing here is two separate activities in the same app set to be launchable, which is completely legal. You can have as many listings in the launcher as you wish. – Gabe Sechan Mar 18 '18 at 08:11

1 Answers1

2

queryIntentActivities retrieves all activities that can be performed for the given intent. So it can returns activites info with same package name.

I believe that Phone and Contacts are the same Contact app.

Two different icons can be created for the same program, one for each different activity. This makes sense, since the MAIN/LAUNCHER intent filter essentially tells android that the activity is the app's starting activity. So if you add this filter to two activities it will give you two icons for the same app to enter different activities. Nothing in android's intent filter model forces each app to have one and only one starting activity.

Rainmaker
  • 10,294
  • 9
  • 54
  • 89
  • Yes, you're right. Upon further examination I notice that they're actually the same app. It raise another question,though. How can I get the label and icon of phone app from the package name? Should I make another question or is it okay to ask here? – AhmadF Mar 18 '18 at 09:42
  • Glad you worked it out. Yet i believe it is not that common! – Rainmaker Mar 18 '18 at 09:43