package com.iaiai;import java.io.BufferedReader;import java.io.DataOutputStream;import java.io.InputStreamReader;import android.app.Activity;import android.os.Bundle;import android.util.Log;/** * * <p> * Title: MainActivity.java * </p> * <p> * E-Mail: [email protected] * </p> * <p> * QQ: 176291935 * </p> * <p> * Http: iaiai.iteye.com * </p> * <p> * Create time: 2011-10-11 * </p> * * @author 丸子 * @version 0.0.1 */public class MainActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); runRootCommand("ls"); } public static boolean runRootCommand(String command) { Process process = null; DataOutputStream os = null; try { process = Runtime.getRuntime().exec("su"); os = new DataOutputStream(process.getOutputStream()); os.writeBytes(command + "\n"); os.writeBytes("exit\n"); os.flush(); process.waitFor(); BufferedReader br = new BufferedReader(new InputStreamReader( process.getInputStream())); // BufferedReader br = new BufferedReader(new InputStreamReader( // process.getErrorStream())); //如果出错用这个输出一下看结果,一定要获取root权限才可以执行 String line = null; while ((line = br.readLine()) != null) { Log.d("*********", line); } try { br.close(); } catch (Exception e) { e.printStackTrace(); } } catch (Exception e) { Log.d("*********", "the device is not rooted, error message: " + e.getMessage()); return false; } finally { try { if (os != null) { os.close(); } if (process != null) { process.destroy(); } } catch (Exception e) { e.printStackTrace(); } } return true; }}
详细解决方案
Android 编纂使用root权限的android应用程序
热度:92 发布时间:2016-05-01 13:33:19.0
相关解决方案
- java.sql.SQLException: Access denied for user 'root'@'localhost' (using password,该如何处理
- java.sql.SQLException: Access denied for user 'root'@'localhost' (using password解决思路
- 网页展示Access denied for user 'root'@'localhost'
- root、root给它整郁闷死了.求解!该怎么处理
- 怎么在外部修改web项目的context-root(web发布名称)
- tomcat起步后spring自动关闭 Closing Spring root WebApplicationContext
- soap调用webservice,报错:Root element of a SOAP message must be: 'http://schemas.xmls,该怎么处理
- android 读取byte[]中的元素解决方案
- android 标题栏兑现方式
- android 中Activity向BroadcastReceiver发送数据,该怎么解决
- Android 4.0 为什么模拟器老是提示小弟我谷歌拼音输入法已停止
- android:getSharedPreferences() 这是哪个类的方法解决思路
- android 怎么判断一个程序是否联网
- android 大量数据按周分组,该如何解决
- android RadioButton如何设置默认选中
- 创建本地文件异常“ Root is not accessible”请高手指教
- 关于JSR75开发 怎么查到 system root name。多谢
- ksoap2-android-这个包,连接webService怎么设置超时
- android 怎么重新设置锚点
- android UI界面设计解决方案
- android 图片对象获取的有关问题
- android 怎么调用淘宝支付宝接口
- Android 沿袭InputMethodService自定义输入法
- android 关于服务连接的疑义
- android 两个activity如何通信
- 高手指教:jsp中出现The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs错误
- android 怎么实现对view的放大和缩小
- android 教程解决方法
- android ID,该如何处理
- 准备复习2-3个月,看java+android,请问有经验者,怎么看效果最好》