转:Android(安卓)获取Root权限
16lz
2022-06-15
来自: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将bitmap保存到自定义路径
- android 从webview中读取缓存的图片
- 视频的播放
- 如何使用ndk中addr2line工具查询so库中错误信息行数
- 手把手--Android(安卓)Studio V3.5.2开发环境搭建及HelloWorld工
- Android(安卓)Recovery模式
- Android之adt 23找不到NDK路径设置解决方案
- Android:Native C源码(NDK)如何使用sqlite3进行编程?
- Android: 模拟器system分区没有可用空间的问题