如何从android应用程序访问sysfs条目
有人能解释一下如何从android应用程序访问sysfs公开的值。 建议我们不能访问的参考是 但也有一个是这样做的如何从android应用程序访问sysfs条目,android,apk,sysfs,Android,Apk,Sysfs,有人能解释一下如何从android应用程序访问sysfs公开的值。 建议我们不能访问的参考是 但也有一个是这样做的 请解释。我经过一些研究后找到了答案 这就是它的工作原理 //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 fr
请解释。我经过一些研究后找到了答案 这就是它的工作原理
//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消息中显示变量/输出
参考资料:
一,
二,
请让我知道是否还有其他方法。我经过一些研究后找到了答案 这就是它的工作原理
//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消息中显示变量/输出
参考资料:
一,
二,
如果还有其他方法,请告诉我。能否在shell脚本中粘贴您正在执行的操作!你能在shell脚本中粘贴你正在做的事情吗!