Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a list of installed android applications and pick one to run

I asked a similar question to this earlier this week but I'm still not understanding how to get a list of all installed applications and then pick one to run.

I've tried:

Intent intent = new Intent(ACTION_MAIN); intent.addCategory(CATEGORY_LAUNCHER); 

and this only shows application that are preinstalled or can run the ACTION_MAIN Intent type.

I also know I can use PackageManager to get all the installed applications, but how do I use this to run a specific application?

like image 674
2Real Avatar asked Apr 23 '10 02:04

2Real


People also ask

How do I track installed apps on Android?

On your Android phone, open the Google Play store app and tap the menu button (three lines). In the menu, tap My apps & games to see a list of apps currently installed on your device. Tap All to see a list of all apps you've downloaded on any device using your Google account.


2 Answers

Here's a cleaner way using the PackageManager

final PackageManager pm = getPackageManager(); //get a list of installed apps. List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);  for (ApplicationInfo packageInfo : packages) {     Log.d(TAG, "Installed package :" + packageInfo.packageName);     Log.d(TAG, "Source dir : " + packageInfo.sourceDir);     Log.d(TAG, "Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName));  } // the getLaunchIntentForPackage returns an intent that you can use with startActivity()  

More info here http://qtcstation.com/2011/02/how-to-launch-another-app-from-your-app/

like image 143
Nelson Ramirez Avatar answered Oct 23 '22 09:10

Nelson Ramirez


Following is the code to get the list of activities/applications installed on Android :

Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); List<ResolveInfo> pkgAppsList = context.getPackageManager().queryIntentActivities( mainIntent, 0); 

You will get all the necessary data in the ResolveInfo to start a application. You can check ResolveInfo javadoc here.

like image 30
Karan Avatar answered Oct 23 '22 08:10

Karan