Android编程中中root权限的获取
来源:互联网 发布:弱网络测试 编辑:程序博客网 时间:2024/05/16 13:50
前几天在做一个文件管理器,在打开非sdcard下的目录文件时碰到了空指针的错误,色友说要获取root权限才能访问其他需root权限的文件夹,于是用了下面的方法获取权限,
public final String rootPowerCommand = "chmod 777 /dev/block/mmcblk0";// 授权root权限命令/** * 授权root用户权限 * * @param command * */ public boolean rootCommand(String command) { Process process = null; DataOutputStream dos = null; try { process = Runtime.getRuntime().exec("su"); dos = new DataOutputStream(process.getOutputStream()); dos.writeBytes(command+"\n"); dos.writeBytes("exit\n"); dos.flush(); process.waitFor(); } catch (Exception e) { return false; } finally { try { if (dos != null) { dos.close(); } process.destroy(); } catch (Exception e) { } } return true; }
虽然调用成功,但是还是空指针错误,如下:
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.list_view); // loadApps(); rootCommand(rootPowerCommand);//调用获取root权限 initTool(); initFileList(); }@Override protected void onListItemClick(ListView l, View v, int position, long id) { @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) this.getListAdapter() .getItem(position); FileBean fileBean = (FileBean) map.get("icon"); Log.v("--------path---------", fileBean.getPath()); File file = new File(fileBean.getPath());//此处路劲fileBean.getPath()经调试得到是存在的目录,如我点击root文件夹得到/root if (!file.isDirectory()) { fileControl.openFile(file);// 打开文件 } else { fileDirControl.openDir(file);// 打开文件夹。。。。。。。。。。。。。。。。接下面 } } /** * 打开目录 * * @param file * */ public void openDir(File file) { fileBroswer.current_path = file.getAbsolutePath(); fileBroswer.currentDir.setText(file.getAbsolutePath()); File[] files = file.listFiles();//得到的files竟然是空的,就是说虽然目录文件存在,但是你不能访问它, data = fileBroswer.getData(files);//由此也就照成了空指针错误,为什么么?求解释啊。。。。。。 MyAdapter myAdapter = new MyAdapter(context, data); fileBroswer.setListAdapter(myAdapter); }
- Android编程中中root权限的获取
- 程序中如何获取Android的Root权限
- 程序中如何获取Android的Root权限
- Android中Root权限获取的实例代码(2)
- Android中Root权限获取的简单代码(3)
- android中Root权限的判断与获取
- Android中Root权限获取(1)
- Ubuntu中获取ROOT权限的方法
- Ubuntu中获取root权限
- Ubuntu中获取root权限
- Ubuntu中获取root权限
- Android应用程序获取ROOT权限的方法(android中如何通过代码检测是否有root权限?)
- Android应用程序获取ROOT权限的方法(android中如何通过代码检测是否有root权限?)
- android在apk中获取root权限,并执行命令
- android在apk中获取root权限,并执行命令
- android在apk中获取root权限,并执行命令
- android在apk中获取root权限,并执行命令
- android在apk中获取root权限,并执行命
- Android应用发布渠道汇总(更新中)
- Oracle深入浅出之一
- 过TP效果测试
- 解决QT开发的exe软件不能运行问题
- 将字符串逆序
- Android编程中中root权限的获取
- GridView按字段升降排序
- poj 1390 Blocks(dp)
- xiewenjian
- git服务器搭建过程
- ASP.net datalist,gridview 编辑模板里面控件的使用;
- Qt:在TreeModel+QTreeView中使用复选框(checkbox)
- Servlet核心介绍之一
- HTML5之学习笔记一