简体   繁体   中英

How to install apps from sd card?

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)

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.

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