简体   繁体   中英

android APK within an APK?

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.

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 .

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 ...

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.

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM