怎么用代码判断android手机是否开启了ROOT 权限

 我来答
小傻

推荐于2018-03-23 · 知道合伙人软件行家
小傻
知道合伙人软件行家
采纳数:11567 获赞数:31138
已经做过两个上架的app和两个网页项目.

向TA提问 私信TA
展开全部
android手机开启了root权限,主要是根据root之后,获取了手机的最高权限,底层linux系统就会生成一个以su结尾的文件,su代表super超级权限,如下代码:
/**
* 判断当前手机是否有ROOT权限
* @return
*/
public boolean isRoot(){
boolean bool = false;

try{
if ((!new File("/system/bin/su").exists()) && (!new File("/system/xbin/su").exists())){
bool = false;
} else {
bool = true;
}
Log.d(TAG, "bool = " + bool);
} catch (Exception e) {

}
return bool;
}
android底层是使用linux进行编译和一些驱动、网络管理的,所以可以根据linux的权限特性来判断是否root,权限的管理在linux里面很多,包括读写、删除文件的权限,也有关于访问网络的权限,这些权限都需要开通才能有。
力控科技
2025-03-07 广告
卸载运行包需要两个步骤:1、手动删除运行包安装后生成文件夹及文件夹中的内容;2、删除注册表(1.Windows2000: 进入windows安装系统盘―>WINNT文件夹―>打开regedit.exe文件―>使用查找功能搜... 点击进入详情页
本回答由力控科技提供
zjacai
2016-03-14 · TA获得超过253个赞
知道小有建树答主
回答量:231
采纳率:0%
帮助的人:126万
展开全部
最直接有效的方式就是执行su命令,su就是切换到root用户,如果su命令可以执行,限则表示root成功。
具体测试方式:
安装进入adb目录(SDK中自带adb)

adb shell 进入shell模式
su 切换到root用户
切换到root用户后会显示一个#号
或直接在android 版本的 shell (附件)中执行命令
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
千锋教育
2016-03-06 · 做真实的自己 用良心做教育
千锋教育
千锋教育专注HTML5大前端、JavaEE、Python、人工智能、UI&UE、云计算、全栈软件测试、大数据、物联网+嵌入式、Unity游戏开发、网络安全、互联网营销、Go语言等培训教育。
向TA提问
展开全部
public class TestRoot {
protected boolean isRoot() {
boolean IsRoot = false;
try {
if (new File("/system/bin/su").exists() || new File("/system/xbin/su").exists()) {
IsRoot = true;
} else {
IsRoot = true;
}
} catch (Exception e) {

}
Log.i("info","isRoot******"+IsRoot);
return IsRoot;
}
}

上面那个是随手写的,你随便看看(其实太简单了,考虑得不周全),下面给个大神的:

/**
* @author Kevin Kowalewski
*
*/
public class Root {

private static String LOG_TAG = Root.class.getName();

public boolean isDeviceRooted() {
if (checkRootMethod1()){return true;}
if (checkRootMethod2()){return true;}
if (checkRootMethod3()){return true;}
return false;
}

public boolean checkRootMethod1(){
String buildTags = android.os.Build.TAGS;

if (buildTags != null && buildTags.contains("test-keys")) {
return true;
}
return false;
}

public boolean checkRootMethod2(){
try {
File file = new File("/system/app/Superuser.apk");
if (file.exists()) {
return true;
}
} catch (Exception e) { }

return false;
}

public boolean checkRootMethod3() {
if (new ExecShell().executeCommand(SHELL_CMD.check_su_binary) != null){
return true;
}else{
return false;
}
}
}

/**
* @author Kevin Kowalewski
*
*/
public class ExecShell {

private static String LOG_TAG = ExecShell.class.getName();

public static enum SHELL_CMD {
check_su_binary(new String[] {"/system/xbin/which","su"}),
;

String[] command;

SHELL_CMD(String[] command){
this.command = command;
}
}

public ArrayList<string> executeCommand(SHELL_CMD shellCmd){
String line = null;
ArrayList<string> fullResponse = new ArrayList<string>();
Process localProcess = null;

try {
localProcess = Runtime.getRuntime().exec(shellCmd.command);
} catch (Exception e) {
return null;
//e.printStackTrace();
}

BufferedWriter out = new BufferedWriter(new OutputStreamWriter(localProcess.getOutputStream()));
BufferedReader in = new BufferedReader(new InputStreamReader(localProcess.getInputStream()));

try {
while ((line = in.readLine()) != null) {
Log.d(LOG_TAG, "--> Line received: " + line);
fullResponse.add(line);
}
} catch (Exception e) {
e.printStackTrace();
}

Log.d(LOG_TAG, "--> Full response was: " + fullResponse);

return fullResponse;
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友e2a349c
2016-03-27 · TA获得超过740个赞
知道小有建树答主
回答量:225
采纳率:75%
帮助的人:62.6万
展开全部
/**
* 判断当前手机是否有ROOT权限
* @return
*/
public boolean isRoot(){
boolean bool = false;

try{
if ((!new File("/system/bin/su").exists()) && (!new File("/system/xbin/su").exists())){
bool = false;
} else {
bool = true;
}
Log.d(TAG, "bool = " + bool);
} catch (Exception e) {

}
return bool;
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
哈哈hyc
推荐于2017-11-22 · 知道合伙人数码行家
哈哈hyc
知道合伙人数码行家
采纳数:9984 获赞数:22367
平时喜欢玩弄一些小数码,生活中也喜欢自己搞搞研究。大家如果有数码类的题目,我会尽力帮助大家的。

向TA提问 私信TA
展开全部
在手机关机状态下,进入手机另外一种模式,然后看下版本号就可以看见有没有root了
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(6)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式