Cómo obtener la ubicación del archivo * .apk en un dispositivo Android

Need some help by retrieving *.apk file name from Android device programmaticaly ? Could any body provide some Android methods doing that or even shell commands run under Android to get the file location , if I know just a part from file name ?

Also if there is a way how to find out where the *.apk file went after downloading from Market or outside Market ?

Gracias de antemano.

preguntado el 08 de enero de 11 a las 18:01

Why do you need this information? -

Perhaps if we knew what you are trying to do it would help in answering the question (since we will have a better idea of what needs to be taken into consideration). -

5 Respuestas

List<ApplicationInfo> PackageManager.getInstalledApplications() will give you a list of the installed applications, and ApplicationInfo.sourceDir is the path to the .apk file.

PackageManager pm = getPackageManager();

for (ApplicationInfo app : pm.getInstalledApplications(0)) {
  Log.d("PackageList", "package: " + app.packageName + ", sourceDir: " + app.sourceDir);
}

Outputs something like this:

package: com.tmobile.themechooser, sourceDir: /system/app/ThemeChooser.apk
package: com.tmobile.thememanager, sourceDir: /system/app/ThemeManager.apk
package: com.touchtype.swiftkey, sourceDir: /data/app/com.touchtype.swiftkey-1.apk
package: com.twitter.android, sourceDir: /data/app/com.twitter.android-2.apk
package: fm.last.android, sourceDir: /data/app/fm.last.android-1.apk

Respondido 25 Feb 12, 11:02

Cuál es la diferencia entre sourceDir y publicSourceDir? Also, do you know why some .apk's have the "-1" or "-2" in their name? - Tony Chan

@Turbo I think the reason is: -1 when is installed for first time and -2 when is not. If you install one app for first time -1 appears if is second, third,... -2 appears. If you install the app for first time and you unistall it and then install again -1 is there - Ivan

I took the code that @therefromhere posted and put it into a small app and built and apk for it in case anyone wants to reuse this on different devices. - zabawaba99

$ adb shell pm list packages -f

Respondido el 12 de Septiembre de 12 a las 10:09

This seems more like a Linux way than programmatical way. - Santosh Kumar

Thanks man, these helped me to detect the current installation directory to backup my apk's. - Walid Ammar

Respondido el 09 de diciembre de 13 a las 07:12

También puedes hacer adb bugreport and look at the output. You'll want to look for <package name="com.app.package" codePath="path/to/the/app.apk"...

Respondido 24 Feb 12, 06:02

The apps that you download go to /data/app así que usando ls you can get a list of the downloaded apks.

Respondido el 08 de enero de 11 a las 21:01

Thank you j3frea. That's default location for Android Market App . I saw that if I am downloading app's form outside (in my case from my Server) the app went to sdcard/download . Can I assume that outside apk's will go always to sdcard/download ? Is that default location for every Android Market app or that path could be changed and is not fixed one ? Is there a way to push the download app just to one location always ? Also is there a method to find a file by name in whole device ? - asteroidg

File dir = new File("/data/app"); File[] fileList = dir.listFiles(); if (fileList != null) { for ( int i = 0;i<fileList.length;i++) { filename = fileList[i].getName(); Log.d("FileLog","file name="+filename); if (-1 != filename.indexOf(appName.toString())) { break; } } } - asteroidg

Do not make any assumptions on directories that are not explicitly outlined in the API. They are bound to change without further notice. Any assumptions like sdcard/download are guaranteed to break at some point. If anything, use directories that are returned by the API, don't use hardcoded paths. And keep in mind that Android Market is not the only way to download apps. - EboMike

Hi EboMike. I don't wanna make any assumption but I need a solution for my problem and I am very surprised that I wasn't able to find any API to help me . Are there any API to get the *.apk file name from the whole device ? Or even path where they can be stored, which are built together with OS ? Thank you. - asteroidg

I think that we need to know what you're trying to do in order to help to solve your problem. - jcuenod

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.