【问题标题】:Working Directory: null Environment:?工作目录:空环境:?
【发布时间】:2015-10-02 09:17:32
【问题描述】:

我正在尝试运行以下代码,我正在使用 [1]:https://github.com/rbochet/Fast-Forward-Reboot 这个链接。

 try {
        Runtime.getRuntime().exec(
                new String[] { "/system/bin/su", "-c", "reboot now" });
    } catch (IOException e) {
        e.printStackTrace();
    }

和错误 W / System.err:java.io.IOException:运行exec()时出错。命令:[/system/bin/su, -c, reboot now] 工作目录:null 环境:null。

权限

android.permission.WRITE_EXTERNAL_STORAGE
android.permission.READ_EXTERNAL_STORAGE
android.permission.WRITE_INTERNAL_STORAGE
android.permission.READ_INTERNAL_STORAGE
android.permission.REBOOT.         

我正在使用 Android Studio,目标是 Android 6.0(API 级别 23) 任何人请有一个想法。提前致谢。

【问题讨论】:

  • 你有解决办法吗?
  • 你找到解决办法了吗?

标签: java android linux android-os-handler


【解决方案1】:
    /**
     * Checks if the device is rooted.
     *
     * @return <code>true</code> if the device is rooted, <code>false</code> otherwise.
     */
    public boolean isRooted() {
        // get from build info
        String buildTags = android.os.Build.TAGS;
        if (buildTags != null && buildTags.contains("test-keys")) {
            return true;
        }
        // check if /system/app/Superuser.apk is present
        try {
            File file = new File("/system/app/Superuser.apk");
            if (file.exists()) {
                return true;
            }
        } catch (Exception exception) {
            // ignore
            exception.printStackTrace();
        }
        String[] commands = {
                "/system/xbin/which su",
                "/system/bin/which su",
                "which su"
        };
        for (String command : commands) {
            try {
                Runtime.getRuntime().exec(command);
                return true;
            } catch (Exception exception) {
                exception.printStackTrace();
            }
        }
        Log.d("message-startUp: ", "RootUtil");
        return false;
    }

如果你的设备没有root,仍然会出现同样的错误

【讨论】:

  • samsung s7通过system/bin/which su,但是明显没有root
【解决方案2】:

"/system/bin/su" 替换为"/system/xbin/su"

【讨论】:

  • 它给了我同样的错误。
猜你喜欢
  • 2014-05-21
  • 1970-01-01
  • 2012-10-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-23
相关资源
最近更新 更多