7

As stated in my question above, is it possible to have an apk file within another apk? To further explain, here is my situation:

I have two apps and the first one calls the other through an intent.. I don't have problem with this.. But what I need is to install only one apk file instead of two. And the first thing that came into my mind is to put a .apk file inside the other .apk file.. I really don't know if this is possible that's why I need your take on this. But if this is not possible, I hope someone can tell me what would be the best practice to doing this kind of thing.

I can make it as one application, but that would be my last solution.

Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
junmats
  • 1,894
  • 2
  • 23
  • 36

4 Answers4

5

I just did that right now ...

I put apk 2 in raw/embeddedapk.apk

then this code ... started the installer for apk 2 ... **problem if user phone doesnt allow application not from market .. it will fail to install apk 2 ...

remember to delete temp file when the instalation is finished ....

try {
    InputStream in = this.getResources().openRawResource(R.raw.embeddedapk);

    byte[] b = new byte[in.available()];
    int read = in.read(b);
    toast(read + " byte read");

    String tempFileName = "embeddedapk.apk";
    FileOutputStream fout = openFileOutput(tempFileName, MODE_WORLD_READABLE);

    fout.write(b);      
    fout.close();
    in.close();

    File tempFile = getFileStreamPath(tempFileName);
    Intent i = getFileActionIntent(Intent.ACTION_VIEW, tempFile);

    startActivity(Intent.createChooser(i, "sdsds"));
}
catch (Exception ex){
    Log.e("ero", "erer", ex);
}

My reason is I want to have apk 1 userinterface and apk 2 data provider as seperate apps in market. but i don't wnat users to down then individually when installing first time ...

  • apk 1 need data from apk 2, apk 2 does not have any activities ..

  • When user downloads apk 1 from market I want to auto instal apk 2 ...

  • I want to be able to update (market) apk1 & apk 2 independantly ...

wattostudios
  • 8,666
  • 13
  • 43
  • 57
TeenInvader
  • 51
  • 1
  • 1
  • about `getFileStreamPath` and `getFileActionIntent`... can you post these too? – SparK Dec 18 '12 at 13:19
  • `Intent.createChooser(i, "sdsds")` is the most important point ! – ben75 Jan 27 '14 at 13:37
  • What if the app is on the marketplace/Play Store - but you are just installing it from within your second APK to save the user from having to download multiple apps? If the signature/binary is the same as the one on Play Store? – RoundSparrow hilltx Mar 08 '17 at 17:07
4

Perhaps an Android Library is what you are looking for. This is a place where you can put some common code and include it in multiple applications (apks).

See this documentation on library projects.

Cheryl Simon
  • 46,552
  • 15
  • 93
  • 82
3

Sorry, you are out of luck if you want APK inside APK.

Android does not allow you to do so.

But I am curious about why you would want it that way ?? You can call one activity from the other even if they are in the same APK.

the100rabh
  • 4,077
  • 4
  • 32
  • 40
  • yes, that's what I stated in the last part of my question.. But I was just wondering if it is possible. The thing is that I made the first app without regards to the second app.. And then I decided to interact the two. But then I still have to install them one by one.. So that's how I came up with my question.. Thanks. – junmats Jan 26 '11 at 01:52
  • If they are in the same APK, they can still call each other, do u want to know how ?? – the100rabh Jan 26 '11 at 01:55
1

You can program it as one application and having two launcher so that it appears to the user as being two stand alone applications.

You could also try to fire the intent and catch the case that no one is reacting on it. Than you can open the market and recommend to install the application, too.

The last way is mostly done by applications that need file browsers to pick files. They send an intent and if there is no file browser installed, they prompting a toast informing that a file browser is needed to perform the task and they open the market page of astro, OI file manager or another app they prefer...

WarrenFaith
  • 57,492
  • 25
  • 134
  • 150