gpt4 book ai didi

java -/sys/上怎么写?安卓

转载 作者:行者123 更新时间:2023-12-02 07:09:34 24 4
gpt4 key购买 nike

我正在尝试写入“/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 访问权限?

最佳答案

普通 SDK 应用程序只能读取系统的该部分。您需要root您的设备,并在 su shell 中执行命令才能在那里写入。

此外,并非所有设备上都存在 amp 文件。

关于java -/sys/上怎么写?安卓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15692783/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com