Wednesday, July 27, 2011

Get the list of activities/applications installed on Android

Following is the code to get the list of activities/applications installed on Android :
 final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
 final List 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.


 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,
 "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/

 To filter on sytem based apps :
 private boolean isSystemPackage(ResolveInfo ri){
 return ((ri.activityInfo.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM)!=0)?true:false;

 }

No comments:

Post a Comment