【问题标题】:How to Access sysfs entry from android application如何从 android 应用程序访问 sysfs 条目
【发布时间】:2013-07-17 13:38:19
【问题描述】:

有人可以在how to access a value exposed by sysfs from an android application.向我解释一下

表明我们无法访问的参考是here

但是有一个android application 可以做到这一点。

请解释一下。

【问题讨论】:

    标签: android apk sysfs


    【解决方案1】:

    经过一番研究,我找到了答案

    这就是它的工作原理。

    //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?

    如果有其他方法,请告诉我。

    【讨论】:

    • 你能把你正在做的事情粘贴到 shell 脚本中吗!
    猜你喜欢
    • 2017-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-05
    • 2021-09-21
    • 2015-06-01
    • 2011-12-19
    • 1970-01-01
    相关资源
    最近更新 更多