版权声明:本文为博主原创文章,转载请标明出处。 https://blog.csdn.net/chaoyu168/article/details/81075850
import android.util.Log;
import java.io.DataOutputStream;
import java.io.File;
/**
* 判断手机是否ROOT
*/
public class isRoot{
public static int root() {
int root = 0;
try {
if ((!new File("/system/bin/su").exists())
&& (!new File("/system/xbin/su").exists())) {
root = 0;
} else {
root = 1;
}
} catch (Exception e) {
}
return root;
}
/**
*
* 判断应用是否有root权限
*/
public static synchronized boolean getRootAhth()
{
Process process = null;
DataOutputStream os = null;
try
{
process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
os.writeBytes("exit\n");
os.flush();
int exitValue = process.waitFor();
if (exitValue == 0)
{
return true;
} else
{
return false;
}
} catch (Exception e)
{
Log.d("*** DEBUG ***", "Unexpected error - Here is what I know: "
+ e.getMessage());
return false;
} finally
{
try
{
if (os != null)
{
os.close();
}
process.destroy();
} catch (Exception e)
{
e.printStackTrace();
}
}
}
}