Process localProcess = Runtime.getRuntime().exec("su");

这条代码获得root权限

OutputStream localOutputStream = localProcess.getOutputStream();

DataOutputStream localDataOutputStream = new DataOutputStream(localOutputStream);

从Process对象获得输出流,然后我们就可以执行Linux命令了

localDataOutputStream.writeBytes(String str);

其中str是String类型的变量。注意在str最后有换行

例如 String str="mkdir /mnt/sdcard/zhycheng\n";


InputStream localInputStream = localProcess.getInputStream();

DataInputStream localDataInputStream = new DataInputStream(localInputStream);

这两条代码获得输出流

例如 String out=localDataInputStream .ReadLine();

这是从控制台输出的

每输出之后调用

localDataOutputStream.flush();

还要调用localProcess .waitFor();

通过调用测试命令int i = execRootCmdSilent("echo test");判断是否获得root权限,i不等于-1就获得了root权限

更多相关文章

  1. android:inputType的XML与Java代码对应关系
  2. Android打开WIFI或者移动网络的代码实现
  3. 【android-tips】android程序执行adb shell命令(实例源码)
  4. Android 访问权限许可大全
  5. android webview显示HTML代码
  6. Android 获取电池基本信息代码
  7. android 打开新浪微博代码
  8. Android 中如何自己通过代码绘图
  9. android 使用代码实现 RelativeLayout布局

随机推荐

  1. android 在代码中获取SHA1值
  2. androidUI设计之旅 ----SeekBar的基本应
  3. Android中正确安全删除集合中的元素
  4. Android Ant打包笔记
  5. 【android 串口开发(二) 之 串口读写操作】
  6. android studio 打jar包并混淆
  7. android 进阶之如何阅读源码
  8. Android(安卓)ActionBar详解(六)--->利用
  9. Android System Property分析(1):property
  10. Android调用微信扫一扫和支付宝扫一扫