Main app download another app then use it

587 Views Asked by At

What I want to do is maybe hard to explain or to understand so I made a quick drawing.enter image description here

First of all, we have 2 Android apps. A display "Hello World" and B has a button which (maybe) can download an app (on web or local).

When we click on B button, that download A app, and install it (like if you download it with any market) and then, use A app to modify B app.

I don't know if it's even possible :

  1. To download app and install it programmatically
  2. Create a "polymorph" Android app like that.

If I have to sum up what I want with one sentence it would be :
Modify B application with A app which B just downloaded and installed.

2

There are 2 best solutions below

6
On

I'm then sure you can download those SDK (apparently as APK here) and use Fragments or any code to inject or something.

Probably will need to use reflection though, because you main application "B" won't resolve the classes that are in "A".

Maybe your "A" modules should expose the methods / variables / fragments it has, like in an embedded JSON descriptive asset or something, that "B" could parse and know what to do with.

The point here is obviously to move all the "A" code away from "B", meaning flexibility for "B".

4
On

To download app and install it programmatically:

Yes you can do it programmatically but the user will be prompted to install the app(like accepting the permissions the new app will use).

    String filename = "yourAppName.apk";
    //trivial downloading asynctask
    DownloadApp appd = new DownloadApp(context, val, filename);
    if (appd.downnAndsave()) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setDataAndType(Uri.fromFile(new File(Environment
                        .getExternalStorageDirectory()
                        + "/download/"
                        + filename)),
                "application/vnd.android.package-archive");
        context.startActivity(intent);
    }

Create a "polymorph" Android app like that:

//if the download is complete then have a flag
//use this to run another application from your application B
    Intent intent = getPackageManager().getLaunchIntentForPackage("com.package.A");
    startActivity(intent);