0

Is there a way for an installed application to get the .apk file of another one? I'm currently writing an analysis app that need to send the .apk to a remote server which will investigate it. I am not sure if this is possible at all.

I don't want to get the .apk file with adb, because this would not help me.

Thanks

null
  • 1,369
  • 2
  • 18
  • 38
  • 2
    ... what for? It seems a **piracy action**, to **steal apks** from the users devices! – Phantômaxx Oct 05 '14 at 15:34
  • I told you: I want to analyze .apk's online. Why should this be a piracy action? I can retrieve any apk by connecting the smartphone to my computer. Therefore I wam wondering if such a behavior is also possible "online". – null Oct 05 '14 at 15:36
  • Noone wants a hacker to analyze their **apks**. – Phantômaxx Oct 05 '14 at 15:38
  • omg...this was just a curious question that came to my mind while thinking about this problem. I had no bad intention. – null Oct 05 '14 at 15:42
  • I suggest that you discuss your plans with a qualified attorney. – CommonsWare Oct 05 '14 at 17:37
  • @null did my solution work for you? – bmat Oct 06 '14 at 15:35
  • Sorry, i just came home and haven't tried it yet. I'll do it tomorrow. If it works I'll mark your answer as correct ;). – null Oct 06 '14 at 16:58

1 Answers1

2

Yes, this can be done. Here's how:

First, you must get a list of all the installed applications. This can be done using the snippet from this SO question:

final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = getPackageManager().queryIntentActivities( mainIntent, 0);

for (Object object : pkgAppsList) {
    ResolveInfo info = (ResolveInfo) object;
    File file =new File( info.activityInfo.applicationInfo.publicSourceDir);
    // copy the .apk file to wherever
}

This allows you to get a File reference for any APK installed on the device. Once you have a File, you can write it to external storage or upload it to a server.

Community
  • 1
  • 1
bmat
  • 2,084
  • 18
  • 24
  • 1
    @NadeemIqbal Yes, it will copy without root privileges. Check Android's "Storage Options" guide for more info on how to copy the files to the SD card. – bmat Oct 05 '14 at 16:39
  • 1
    I works. In order to select a specific app, you still must add the if statement `if (info.activityInfo.packageName.equals(myApp))` – null Oct 09 '14 at 10:45