How to install apps from sd card?

391 views Asked by At

My code is supposed to install my app called "xadb-build.apk", But it does nothing, no errors, no force closes, I only see the super user permission granted toast. Here is my approach

File sdCard = Environment.getExternalStorageDirectory();
    String fileStr = sdCard.getAbsolutePath() + "/download";// +
                                                            // "app-release.apk";

    File file = new File(fileStr, "xadb-build.apk");

    if (file.exists()) {
        try {
            String command;
            command = "adb install -r " + file;
            Process proc = Runtime.getRuntime().exec(
                    new String[] { "su", "-c", command });
            proc.waitFor();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

I got this code from here (see palak's answer)

1

There are 1 answers

2
Star_Man On

Android supports this method.

File apkFile = new File({path to APK});
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
        startActivity(intent);

And your method is not recommended.