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?
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.
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/
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.
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