获取错误“;根访问被拒绝”;在android应用中
运行此代码时,我收到一个错误,错误为“根访问被拒绝[java.io.IOException]:运行exec()时出错。命令:[su]工作目录:null环境:null”获取错误“;根访问被拒绝”;在android应用中,android,Android,运行此代码时,我收到一个错误,错误为“根访问被拒绝[java.io.IOException]:运行exec()时出错。命令:[su]工作目录:null环境:null” 这是因为应用程序在android系统中没有超级用户权限 如果您的手机具有root访问权限,则可以使用进程和运行时类启动shell脚本 请参阅以下链接:- 首先。。。你需要让你的设备扎根。有点帮助 如果您的应用程序将在匿名客户端设备上运行,那么您最好首先检查该设备是否为根用户。我的库有一个根可用性检查方法,如下所示,但在少数情况下
这是因为应用程序在android系统中没有超级用户权限 如果您的手机具有root访问权限,则可以使用进程和运行时类启动shell脚本 请参阅以下链接:-
首先。。。你需要让你的设备扎根。有点帮助 如果您的应用程序将在匿名客户端设备上运行,那么您最好首先检查该设备是否为根用户。我的库有一个根可用性检查方法,如下所示,但在少数情况下不起作用
public static boolean hasRoot() {
String tags = Build.TAGS;
if ((tags != null) && tags.contains("test-keys"))
return true;
try {
if (new File("/system/app/Superuser.apk").exists())
return true;
} catch (Exception exception) {
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();
}
}
return false;
}
然后,您可以继续执行执行超级用户shell的过程并检查uid
或者,如果你想简化事情,你可以看看我的开源Android CLI库,使用它,这个任务会更简单。您可以找到github项目。我正在尝试实现一个代码,其中我需要使用android压缩视频,但找不到任何相关的API来实现。请您指导我好吗?我正在尝试实现一个代码,其中我需要使用android压缩视频,但找不到任何相关的API来实现。您可以指导我吗请?使用此代码时,它会显示“java.io.IOException:运行exec()时出错。命令:[/system/xbin/which,su]工作目录:null环境:null”很可能您当时没有根目录。先去生根,然后继续。
public static boolean hasRoot() {
String tags = Build.TAGS;
if ((tags != null) && tags.contains("test-keys"))
return true;
try {
if (new File("/system/app/Superuser.apk").exists())
return true;
} catch (Exception exception) {
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();
}
}
return false;
}