android程序执行adb shell命令
16lz
2021-01-23
文章转载自:http://blog.csdn.net/buptgshengod
final String FILE_NAME = "cat data/misc/wifi/wpa_supplicant.conf";
if(DEBUG) Log.d("chenshichun"," "+this.getClass().getCanonicalName()+" ::::::::: exec(FILE_NAME)::"+ exec(FILE_NAME));
private String exec(String command) { try { Process process = Runtime.getRuntime().exec(command); BufferedReader reader = new BufferedReader( new InputStreamReader(process.getInputStream())); int read; char[] buffer = new char[4096]; StringBuffer output = new StringBuffer(); while ((read = reader.read(buffer)) > 0) { output.append(buffer, 0, read); } reader.close(); process.waitFor(); return output.toString(); } catch (IOException e) { throw new RuntimeException(e); } catch (InterruptedException e) { throw new RuntimeException(e); } }
备注:要操作data/下面的要保证有root权限和读写权限
chmod 777 /data/misc/wifi/wpa_supplicant.conf
可以用下面方法检测是否有root权限
RootTools.isRootAvailable()
如果在PhoneWindowManager.java中写则不需要管权限,他的权限比较高
更多相关文章
- android 模拟器获得root 权限
- Android应用程序获取ROOT权限的方法(android中如何通过代码检测
- android(7)(写数据权限)
- Android 开机自启和后台自启权限
- android典型代码系列(十)------获取一个应用程序的权限信息(反射
- 【Android】Android 权限大全
- Android SDK1.0 Permission 大全访问权限许可
- 关于Android的app权限申请问题
- 在Android中通过Java修改文件权限