
怎么用代码判断android手机是否开启了ROOT 权限
8个回答
展开全部
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里面很多,包括读写、删除文件的权限,也有关于访问网络的权限,这些权限都需要开通才能有。
/**
* 判断当前手机是否有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文件―>使用查找功能搜...
点击进入详情页
本回答由力控科技提供
展开全部
最直接有效的方式就是执行su命令,su就是切换到root用户,如果su命令可以执行,限则表示root成功。
具体测试方式:
安装进入adb目录(SDK中自带adb)
adb shell 进入shell模式
su 切换到root用户
切换到root用户后会显示一个#号
或直接在android 版本的 shell (附件)中执行命令
具体测试方式:
安装进入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;
}
}
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;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
/**
* 判断当前手机是否有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;
}
* 判断当前手机是否有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;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在手机关机状态下,进入手机另外一种模式,然后看下版本号就可以看见有没有root了
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |