How to Get a List of Installed Android Applications and Pick One to Run

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

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.

Get a list of installed applications in android

Use these methods in your activty to get a list of installed applications.

  private ArrayList<PackageInfoStruct> getPackages() {
ArrayList<PackageInfoStruct> apps = getInstalledApps(false);
final int max = apps.size();
for (int i=0; i < max; i++) {
apps.get(i);
}
return apps;
}

private ArrayList<PackageInfoStruct> getInstalledApps(boolean getSysPackages) {

List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
try{
app_labels = new String[packs.size()];
}catch(Exception e){
Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_SHORT).show();
}
for(int i=0;i < packs.size();i++) {
PackageInfo p = packs.get(i);
if ((!getSysPackages) && (p.versionName == null)) {
continue ;
}
PackageInfoStruct newInfo = new PackageInfoStruct();
newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
newInfo.pname = p.packageName;
newInfo.versionName = p.versionName;
newInfo.versionCode = p.versionCode;
newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
res.add(newInfo);

app_labels[i] = newInfo.appname;
}
return res;
}

How to get the list of apps that have been installed by a user on an Android device?

// Flags: See below
int flags = PackageManager.GET_META_DATA |
PackageManager.GET_SHARED_LIBRARY_FILES |
PackageManager.GET_UNINSTALLED_PACKAGES;

PackageManager pm = getPackageManager();
List<ApplicationInfo> applications = pm.getInstalledApplications(flags);
for (ApplicationInfo appInfo : applications) {
if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {
// System application
} else {
// Installed by user
}
}

Flags:

  • GET_META_DATA
  • GET_SHARED_LIBRARY_FILES
  • GET_UNINSTALLED_PACKAGES

How to get list of ALL apps (including System Apps)?

You are already getting a list of all installed applications including the system apps by calling this:

List<ApplicationInfo> apps = getPackageManager().getInstalledPackages(0);

Those with the flags:

  • ApplicationInfo.FLAG_UPDATED_SYSTEM_APP
  • ApplicationInfo.FLAG_SYSTEM

are system apps. You can check for the flags like this:

List<ApplicationInfo> apps = getPackageManager().getInstalledApplications(0);
for(ApplicationInfo app : apps) {
if((app.flags & (ApplicationInfo.FLAG_UPDATED_SYSTEM_APP | ApplicationInfo.FLAG_SYSTEM)) > 0) {
// It is a system app
} else {
// It is installed by the user
}
}

Get list of installed applications within library Android

You will generally have to add Context parameter to your library API, to init function for example, and pass a Context from the application that uses it.

However, there is a hackish workaround (single-line, to highlight that it's an ugly hack):

if (Runtime.getRuntime().exec(new String[]{"/system/bin/sh","-c","cd /data/data/jackpal.androidterm"}).waitFor() == 0) { Log.d("!!!", "Android Terminal Emulator app is installed"); }

This code will check if the private app directory exists in Andorid filesystem.
You cannot list private directory of another app, or open any files from it, however you can check if the directory itself exists just by trying to chdir there.

List out installed/running applications in android programmatically

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);

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

To check all running applications

ActivityManager actvityManager = (ActivityManager)
this.getSystemService( ACTIVITY_SERVICE );
List<RunningAppProcessInfo> procInfos = actvityManager.getRunningAppProcesses();

Referred From: http://www.dreamincode.net/forums/topic/138412-android-20-list-of-running-applications/

Note: Above described function will return correct result for below API 21, for 21 and above it's deprecated.



Related Topics



Leave a reply



Submit