Android How to - Get all packages from Context








Question

We would like to know how to get all packages from Context.

Answer

import java.util.ArrayList;
import java.util.List;
/*from   w  w  w  .  j  a  v a 2s.  co  m*/
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

public class Main {

  public static List<PackageInfo> getAllPackages(Context context) {
    List<PackageInfo> packageList = new ArrayList<PackageInfo>();
    PackageManager pm = context.getPackageManager();
    packageList = pm.getInstalledPackages(0);
    return packageList;
  }
}