Does Android keep the .apk files? if so where?
You can use package manager (pm
) over adb shell
to list packages:
adb shell pm list packages | sort
and to display where the .apk
file is:
adb shell pm path com.king.candycrushsaga
package:/data/app/com.king.candycrushsaga-1/base.apk
And adb pull
to download the apk.
adb pull data/app/com.king.candycrushsaga-1/base.apk
Preinstalled applications are in /system/app
folder. User installed applications are in /data/app
. I guess you can't access unless you have a rooted phone.
I don't have a rooted phone here but try this code out:
public class Testing extends Activity {
private static final String TAG = "TEST";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
File appsDir = new File("/data/app");
String[] files = appsDir.list();
for (int i = 0 ; i < files.length ; i++ ) {
Log.d(TAG, "File: "+files[i]);
}
}
It does lists the apks in my rooted htc magic and in the emu.
If you just want to get an APK file of something you previously installed, do this:
- Get AirDroid from Google Play
- Access your phone using AirDroid from your PC web browser
- Go to Apps and select the installed app
- Click the "download" button to download the APK version of this app from your phone
You don't need to root your phone, use adb
, or write anything.
There is no standard location, however you can use the PackageManager to find out about packages and the ApplicationInfo class you can get from there has various information about a particular package: the path to its .apk, the path to its data directory, the path to a resource-only .apk (for forward locked apps), etc. Note that you may or may not have permission to read these directories depending on your relationship with the other app; however, all apps are able to read the resource .apk (which is also the real .apk for non-forward-locked app).
If you are just poking around in the shell, currently non-forward-locked apps are located in /data/app/.apk. The shell user can read a specific .apk, though it can't list the directory. In a future release the naming convention will be changed slightly, so don't count on it remaining the same, but if you get the path of the .apk from the package manager then you can use it in the shell.
Preinstalled Apps are typically in /system/app and user installed apps are in /data/app.
You can use "adb pull", but you need to know the full path of the APK file. On the emulator, you can get a directory listing using "adb shell" + "ls". But on an android device, you will not be able to do that in "/data" folder due to security reasons. So how do you figure out the full path of the APK file?
You can get a full list of all apps installed by writing a program that queries the PackageManager. Short code snippet below:
PackageManager pm = getPackageManager();
List<PackageInfo> pkginfo_list = pm.getInstalledPackages(PackageManager.GET_ACTIVITIES);
List<ApplicationInfo> appinfo_list = pm.getInstalledApplications(0);
for (int x=0; x < pkginfo_list.size(); x++){
PackageInfo pkginfo = pkginfo_list.get(x);
pkg_path[x] = appinfo_list.get(x).publicSourceDir; //store package path in array
}
You can also find apps that will give such info. There are lots of them. Try this one (AppSender).