简体   繁体   中英

How can I install a “bundle” of applications (apk's) on device with prompting user only once

My application is based on multiple applications (each one has different apk signatures). I want to install one apk and after one confirmation the device should install all applications in the "bundle".

I managed to install the bundle of applications but after every installation I have a confirmation before installing(see below).

I need this to be a seamless process where the user will only have to confirm the installation process only once.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    installAPK(R.raw.apk0, 0);
}

private void installAPK(int apk, int apk_code) {
    try {


        InputStream in = this.getResources().openRawResource(apk);

        byte[] b = new byte[in.available()];

        int read = in.read(b);

        // String tempFileName = "currentapk.apk";

        FileOutputStream fout = openFileOutput(tempFileName,
                MODE_WORLD_READABLE);

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

        File tempFile = getFileStreamPath(tempFileName);

        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(tempFile),
                "application/vnd.android.package-archive");
        startActivityForResult(Intent.createChooser(intent, "install"),
                apk_code);
    }

    catch (Exception ex) {
        ex.printStackTrace();
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    File tempFile = getFileStreamPath(tempFileName);

    if (tempFile.delete()) {
        Log.d("******PACKAGING******", "FILE DELETED!");
    }

    switch (requestCode) {
    case 0: {

        installAPK(R.raw.apk1, 1);
        break;
    }

    case 1: {
        installAPK(R.raw.apk2, 2);
        break;
    }
          case 2: {
        installAPK(R.raw.apk3, 3);
        break;
    }

Any idea how I can get this to install with prompting the user only once?

I need this to be a seamless process where the user will only have to confirm the installation process only once.

Fortunately, this is not possible -- as zapi notes, for security reasons. Users have the right to know what is being installed and to have the ability to say "no, I do not want that".

Of course, you are welcome to create your own ROM mod that has all these apps built in, then convince people to install that ROM. This eliminates the per-app user choice. A business that wishes to distribute devices with apps pre-installed would go this route, not only to avoid the prompting, but to prevent people from uninstalling those apps once they get their modded device.

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