Android How to - Get APK file path








Question

We would like to know how to get APK file path.

Answer

/*from   ww w  .  ja  v  a 2s  .  c  o m*/
import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

public class Main {

  public static List<String> getApkPath(Context context) {
      List<String> apkPathList = new ArrayList<String>();
      PackageManager pm = context.getPackageManager();
      List<PackageInfo> pkginfolist = pm.getInstalledPackages(0);
      for (int i = 0; i < pkginfolist.size(); i++) {
          String sourceDir = pkginfolist.get(i).applicationInfo.sourceDir;
          apkPathList.add(sourceDir);
      }
      return apkPathList;
  }
}