Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
511 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...