KK_07k11A0585 KK_07k11A0585 - 1 year ago 62
Android Question

How to get the .apk file of an application programatically

I want to create an application which has the following functionality. It should save its
.apk file to the sdcard. Imagine I have a

. On clicking it I have to save the .apk file of the application.

Answer Source

It is easy to do that..

  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);
List<ResolveInfo> apps = getPackageManager().queryIntentActivities(mainIntent, 0);
for (ResolveInfo info : apps) {
    File file = new File(info.activityInfo.applicationInfo.publicSourceDir);
    // Copy the .apk file to wherever