How to get the .apk file of an application programmatically

android

Solution

It is easy to do that..

- First you get all installed applications,

- For each one, get public source directory.

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

Problem

I want to create an application which has the following functionality. It should save its .apk file to the sdcard. Imagine I have a `Button`. On clicking it I have to save the .apk file of the application.

Original source

Related problems