需要讀寫 "/sys/devices/virtual/timed_output/vibrator/amp" 文件
我可以正常讀,但是不知道怎麼寫。
代碼如下:
public static void writeValue(String filename, String value) {
//FileOutputStream fos = null;
DataOutputStream os = null;
try {
/*fos = new FileOutputStream(new File(filename), false);
fos.write(value.getBytes());
fos.flush();*/
Process p;
p = Runtime.getRuntime().exec("su");
os = new DataOutputStream(p.getOutputStream());
os.writeBytes(value + " > " + filename + "\n");
os.writeBytes("exit\n");
Log.w(TAG, value + " >> " + filename);
os.flush();
} catch (IOException e) {
Log.w(TAG, "Could not write to " + filename);
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {
Log.d(TAG, "Could not close " + filename, e);
}
}
}
}
我得到** Log.w(TAG, "Could not write to " + filename); **的返回值。
不知道應該怎麼寫入?需要什麼許可麼?要不要全部重建來匹配root訪問?
os.writeBytes(value + " > " + filename + "\n");
這句不對
試試:
os.writeBytes("echo '"+value + "' > " + filename + "\n");
或者:
os.writeBytes("echo -n '"+value + "' > " + filename + "\n");