1

I want to launch all installed applications from my application.Here i get all installed applications

List<ApplicationInfo> applicationInfoList = packageManager.getInstalledApplications(PackageManager.GET_ACTIVITIES | PackageManager.GET_META_DATA);
if(applicationInfoList != null && !applicationInfoList.isEmpty()){
    Collections.sort(applicationInfoList, new ApplicationInfo.DisplayNameComparator(
            packageManager));
    for (ApplicationInfo applicationInfo : applicationInfoList) {
        Intent intent = packageManager.getLaunchIntentForPackage(applicationInfo.packageName);
        if(intent != null){
            ComponentName componentName = intent.getComponent();
            //add componenet to a list
        }

    }
}

But i can't launch some applications like Contacts and Phone.The class name is 'ResolverActivity' for these apps.How ca i launch these apps from my applications?

Thanks in Advance

Devu Soman
  • 2,138
  • 12
  • 32
  • 55

2 Answers2

1

This is because Contacts and Phone are the same application, as are Maps and Latitude. They happen to have multiple launchable activities.

So, you have two choices:

  1. Stick with your statement that you want to "launch all installed applications", in which case your existing code is correct (the user will choose whether to show Contacts or Phone), or

  2. Do what a home screen launcher does, which is "launch all launchable activities", in which case you are going about it wrong

For the latter, use queryIntentActivities() for a MAIN/LAUNCHER Intent, and use the results to build your list. Here is a sample application that demonstrates this.

CommonsWare
  • 910,778
  • 176
  • 2,215
  • 2,253
0

to launch an application you can try this :

        // start the app by invoking its launch intent
        Intent i = getPackageManager().getLaunchIntentForPackage(applicationInfo.packageName);
        try {
           if (i != null) {
              startActivity(i);
           } else {
              i = new Intent(applicationInfo.packageName);
              startActivity(i);
           }
        } catch (ActivityNotFoundException err) {
           Toast.makeText(ListInstalledApps.this, "Error launching app", Toast.LENGTH_SHORT).show();
        }

refer this : tutorial1 , tutorial2 , thread stackoverflow

Community
  • 1
  • 1
Houcine
  • 22,593
  • 13
  • 53
  • 83