0

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)

Community
  • 1
  • 1
bad mom
  • 61
  • 6
  • Did you try using `pm install` instead of `adb install` as one of the comments to palak's answer suggests? – Ted Hopp Dec 26 '16 at 03:22
  • `getExternalStorageDirectory();`. That is not the sdcard but external memory. Where are you talking about? – greenapps Dec 26 '16 at 09:35

1 Answers1

0

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.

Star_Man
  • 1,091
  • 1
  • 13
  • 30