工作目录:null环境:? [英] Working Directory: null Environment:?

查看:137
本文介绍了工作目录:null环境:?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to run below code,I am using [1]:https://github.com/rbochet/Fast-Forward-Reboot this link.

 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,立即重新启动]工作目录:null环境:null.

And Error W/System.err﹕ java.io.IOException: Error running exec(). Command: [/system/bin/su, -c, reboot now] Working Directory: null Environment: 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) 有人请有个主意.预先感谢.

I am using Android Studio ,Target Android 6.0 (API level 23) Anybody please have an idea. thanks in advance.

推荐答案

    /**
     * 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,仍然会出现相同的错误

if your device unrooted, still will bring up the same error

这篇关于工作目录:null环境:?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆