我有su权限,用adb可以修改成功,但是用代码就不行了,一直报Stream Close错误,哪位老哥实现过类似操作的?我用了三种方法,都不行 public void openCM(){
// String[] commands = new String[] { "/system/bin/sh", "-c", "chmod -R 777 /dev/video0" };
String[] commands = new String[] {"chmod -R 777 /dev/video0"};
Process process = null;
DataOutputStream dataOutputStream = null;
try {
process = Runtime.getRuntime().exec("su");
dataOutputStream = new DataOutputStream(process.getOutputStream());
int length = commands.length;
for (int i = 0; i < length; i++) {
dataOutputStream.writeBytes(commands[i] + "\n");
}
// dataOutputStream.writeBytes("exit\n");
dataOutputStream.flush();
process.waitFor();
} catch (Exception e) {
Log.d(TAG,"发生错误"+e.getMessage());
} finally {
try {
if (dataOutputStream != null) {
dataOutputStream.close();
}
process.destroy();
} catch (Exception e) {
Log.d(TAG,e.getMessage());
}
}
}参考了很多老哥的方法,依旧不能获取到读写权限
// String[] commands = new String[] { "/system/bin/sh", "-c", "chmod -R 777 /dev/video0" };
String[] commands = new String[] {"chmod -R 777 /dev/video0"};
Process process = null;
DataOutputStream dataOutputStream = null;
try {
process = Runtime.getRuntime().exec("su");
dataOutputStream = new DataOutputStream(process.getOutputStream());
int length = commands.length;
for (int i = 0; i < length; i++) {
dataOutputStream.writeBytes(commands[i] + "\n");
}
// dataOutputStream.writeBytes("exit\n");
dataOutputStream.flush();
process.waitFor();
} catch (Exception e) {
Log.d(TAG,"发生错误"+e.getMessage());
} finally {
try {
if (dataOutputStream != null) {
dataOutputStream.close();
}
process.destroy();
} catch (Exception e) {
Log.d(TAG,e.getMessage());
}
}
}参考了很多老哥的方法,依旧不能获取到读写权限
解决方案 »
- 【开发分享】如何提高移动应用的活跃度
- android无线点餐系统
- android 如何朗读中文?
- 关于TextView不断赋值的问题
- 我想去做android开发,大伙给点建议吧
- webview的getProgress()方法在loadString时,百分比还会那么明显吗?
- android4.0如何关闭logcat功能(帮顶也给分)
- 想测试安卓app的启动时间,一般安卓设备logcat里面有app启动时间log,但三星的都是process ***has died
- android gridview 怎么设置多个item的背景色改变
- 我开发的一个游戏上传到GOOGLEPLAY后下载量和访问量都为0,这正常吗?
- android Activity切换8次固定发送socket中断
- 求怎么调试没有默认activity的程序
//获取权限
File device = new File("/dev/video0");
if (!device.canRead() || !device.canWrite()) {
try {
/* Missing read/write permission, trying to chmod the file */
Process su;
su = Runtime.getRuntime().exec("su");
String cmd = "chmod 777 /dev/video0\nexit\n";
su.getOutputStream().write(cmd.getBytes());
if ((su.waitFor() != 0) || !device.canRead() || !device.canWrite()) {
Log.d(TAG,"获取权限失败");
return;
}
Log.d(TAG,"获取权限成功");
} catch (Exception e) {
e.printStackTrace();
Log.d(TAG,"获取权限失败");
return;
}
}
}