码迷,mamicode.com
首页 > 移动开发 > 详细

转:Android 获取Root权限

时间:2014-12-07 17:45:38      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:des   android   style   blog   http   io   ar   os   sp   

来自:http://blog.csdn.net/twoicewoo/article/details/7228940


import java.io.DataOutputStream; import android.app.Activity; public class MyTestPri extends Activity{ public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); //* Create a TextView and set its content. //* the text is retrieved by calling a native //* function. setContentView(R.layout.main); String apkRoot="chmod 777 /dev/block/mmcblk0";//SD卡分区路径,也可能是mmcblk1随系统版本定,当前程序路径请用getPackageCodePath(); RootCmd(apkRoot); } public boolean RootCmd(String cmd){ Process process = null; DataOutputStream os = null; try{ process = Runtime.getRuntime().exec("su"); os = new DataOutputStream(process.getOutputStream()); os.writeBytes(cmd+ "\n"); os.writeBytes("exit\n"); os.flush(); process.waitFor(); } catch (Exception e) { return false; } finally { try { if (os != null) { os.close(); } process.destroy(); } catch (Exception e) { } } return true; } }

 

转:Android 获取Root权限

标签:des   android   style   blog   http   io   ar   os   sp   

原文地址:http://www.cnblogs.com/zuiyirenjian/p/4149601.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!