老哥们,在安卓6.0以上,我想在代码中改变文件的读写权限,不成功,可能是什么原因呢?
我有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());
}
}
}
参考了很多老哥的方法,依旧不能获取到读写权限