【问题标题】:How to install apps from sd card?如何从 SD 卡安装应用程序?
【发布时间】:2016-12-26 02:35:43
【问题描述】:

我的代码应该安装我的名为“xadb-build.apk”的应用程序,但它什么也没做,没有错误,没有强制关闭,我只看到授予 toast 的超级用户权限。这是我的方法

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();
        }
    }

}

我从here 得到这个代码(见 palak 的回答)

【问题讨论】:

  • 您是否尝试过使用 pm install 而不是 adb install 作为 palak 回答的 cmets 之一?
  • getExternalStorageDirectory();。那不是SD卡,而是外部存储器。你在说什么?

标签: android root su


【解决方案1】:

Android 支持此方法。

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);

而且不推荐你的方法。

【讨论】:

  • 这意味着,“检查答案!”
  • root only. 。没有。路!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-11
  • 2011-04-04
  • 2015-04-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多