How to save apk sahre apk file and backup

How to get apk file in Android device programatically

In this tutorial we will see how to save and share installed APK from the device. In this post we will see how we can copy or share apk file of applications installed in the user device.

Steps to save APK file:

  1. Get list of installed applications in the device.
  2. Get public source directory of the application
  3. Make a copy of apk file from public source directory to desired location.

Get List Of Apps:

First we will call PackageManager getInstalledApplications api to get information of installed application. getInstalledApplications returns all the applications installed for the user.

We will create a handler thread to get the list of applications installed in a background thread.

We will be using HandlerThread to get the list of apps in background thread. After receiving installed application list HandlerThread will pass the list back to main UI thread.


RecyclerView to Show List Of Installed Apps:

get list of all apps installed in android

We have fetched list of apps installed in the device. Now it’s time to create RecyclerView Adapter to display the list in the view.

Create adapter class

Create layout view app_row.xml

Save APK file to SD-card with AsyncTask

In order to get apk file we need to filter application list based on package name and get its public source directory. Once we get the path to the apk file we can copy it to sdcard. Let’s create a simple AsyncTask to copy apk file from source to destination.

We have created a AsyncTask and we pass Context and ApplicationInfo of the source application as parameters. ApplicationInfo contains information about the package like label, icon, apk location.

This is how our asynctask needs to be called.

Download Android Source Code

The code demonstrates how to fetch list of all the apps in a background thread created using HandlerThread. Furthermore it also shows how to save the apk file of the selected app in SD-Card location.

APK Save Code
APK Save Code
Version: 1.0
200.9 KiB

Leave a Reply