Read .apk from another application from my own application

advertisements

Is there any way to scan .apk files of other apps from my own app without root access? There should be because there are apps like APK Extractor that offer you to get .apk of any installed application. Best thing is, APK Extractor doesn't require root access.

I tried doing this by using ProcessBuilder and calling command pm list packages to get installed packages, then I'd run pm path com.package.name to get path of each .apk. I get valid paths but when I try to open it using File apkFile = new File(apkPath); I get

java.io.FileNotFoundException: /data/app/some.app.package/base.apk
open failed: ENOENT (No such file or directory)

which basically means I don't have right permissions to read that file.


I found solution in another question, here is direct link to answer in another thread.

I also copied answer here for lazy people.

  1. First you get all installed applications,
  2. For each one, get public source directory.
  3. copy the file to the SDCard.

Note: No need to be rooted.

Here is the snippt code:

final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = getPackageManager().queryIntentActivities(mainIntent, 0);
for (Object object : pkgAppsList) {
    ResolveInfo info = (ResolveInfo) object;
    File file = new File(info.activityInfo.applicationInfo.publicSourceDir);
    // Copy the .apk file to wherever
}