Reputation: 414
I'm trying to writte on "/sys/devices/virtual/timed_output/vibrator/amp" file.
I can read it just fine, the problem is when i try to writte it.
Here's my code:
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);
}
}
}
}
I'm always getting the feedback from Log.w(TAG, "Could not write to " + filename);
How do I proceed about that? Do I have to use some permissions? Has it to be all remade to match root access?
Upvotes: 1
Views: 1178
Reputation: 45568
os.writeBytes(value + " > " + filename + "\n");
is wrong. Try
os.writeBytes("echo '"+value + "' > " + filename + "\n");
or
os.writeBytes("echo -n '"+value + "' > " + filename + "\n");
.
Upvotes: 0
Reputation: 82543
Normal SDK applications only have read access to that part of the system. You will need to root your device, and execute commands in a su
shell to write over there.
Also, the amp
file doesn't exist on all devices.
Upvotes: 3