【发布时间】:2013-07-17 13:38:19
【问题描述】:
有人可以在how to access a value exposed by sysfs from an android application.向我解释一下
表明我们无法访问的参考是here
但是有一个android application 可以做到这一点。
请解释一下。
【问题讨论】:
有人可以在how to access a value exposed by sysfs from an android application.向我解释一下
表明我们无法访问的参考是here
但是有一个android application 可以做到这一点。
请解释一下。
【问题讨论】:
经过一番研究,我找到了答案
这就是它的工作原理。
//cmd will be the path of script to be executed
String cmd = "/home_dir/./my_shell_script.sh" ;
Runtime run = Runtime.getRuntime() ;
//this will run the script from java
Process pr = run.exec(cmd) ;
返回的值可以这样读取
BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
try {
String string = buf.readLine();
char[] text = string.toCharArray();
int start = 0;
int len = string.length();
textView.setText(text, start, len);
Toast.makeText(this, string, Toast.LENGTH_SHORT).show();
}
catch (IOException e)
{
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
它将在 toast 消息中显示变量/输出。
参考资料:
1 Executing shell command from java
2/sys/devices/virtual/gpio access from Java?
如果有其他方法,请告诉我。
【讨论】: