I'm trying to get the path of my current running apk on android. I'm using System.getProperty("user.dir"). But it gives out a "/", which is the root directory of the Android system. Am i missing something?
-
1And what do you expect it to be ? – Konstantin Yovkov May 18 '13 at 00:22
-
1@kocko I was mroe expecting a "/user/apk/myapkname"...something like that – henryyao May 18 '13 at 00:25
4 Answers
As the documentation says, the user.dir
property is the user working directory, which is not necessarily the same as the directory where your apk is placed.
Anyway, the List<ApplicationInfo> PackageManager.getInstalledApplications()
will give you a list of the installed applications, and ApplicationInfo.sourceDir
is the path to the .apk
file.
Here's some sample code:
PackageManager pm = getPackageManager();
for (ApplicationInfo app : pm.getInstalledApplications(0)) {
System.out.println("SourceDir: " + app.sourceDir);
}
The above will give you the sourcepath for all the installed apks.
The example is taken from here.

- 1
- 1

- 62,134
- 8
- 100
- 147
Your apk is located at /data/app/<your_package_name>
after installation on the internal memory. This path is consistent across Android, and you don't need to use System
.

- 81,899
- 22
- 187
- 195
Check the Context class. The functions you want are:
- getDir() -- returns e.g. "/data/data/com.example.myapp/app_foo"
- getFilesDir() -- returns e.g. "/data/data/com.example.myapp/files"
- getCacheDir() -- returns e.g. "/data/data/com.example.myapp/cache"
- getExternalFilesDir() -- returns e.g. "/sdcard/Android/data/com.example.myapp/files/Pictures"
- getExternalCacheDir() -- returns e.g. "/sdcard/Android/data/com.example.myapp/cache"
and so forth.

- 9,991
- 11
- 77
- 112
The ApplicationInfo class is your answer:
PackageManager pm = getPackageManager();
for (ApplicationInfo app : pm.getInstalledApplications(0)) {
if (app.packageName.equals(appPackage) { Log.i( app.sourceDir); }
}
Hope that sorts you.

- 33,938
- 5
- 80
- 91