您的位置:首页 > 运维架构 > Shell

android程序执行adb shell命令

2017-11-04 17:13 337 查看
文章转载自: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);
}
}


<uses-permission android:name="android.permission.INTERNET"></uses-permission>


备注:要操作data/下面的要保证有root权限和读写权限

chmod 777 /data/misc/wifi/wpa_supplicant.conf


可以用下面方法检测是否有root权限
RootTools.isRootAvailable()


如果在PhoneWindowManager.java中写则不需要管权限,他的权限比较高
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: