Android應用執行adb命令獲取一些需要的信息

廢話不多說,直接上代碼:

private void getInfo() {
    BufferedReader reader = null;
    String content = "";
    try {
        Process process = Runtime.getRuntime().exec("getprop ro.build.fingerprint");
        reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
        StringBuffer output = new StringBuffer();
        int read;
        char[] buffer = new char[1024];
        while ((read = reader.read(buffer)) > 0) {
            output.append(buffer, 0, read);
        }
        reader.close();
        content = output.toString();
        Log.d("manman", "content = " + content);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

上面的代碼類似執行了如下操作:

adb shell getprop ro.build.fingerprint

不是所有的應用都能有權限執行一些操作。有的是需要有相應的權限的。比如應用有系統簽名,運行在系統進程,就有比較高的權限。
這些主要是涉及到SElinux相關的內容。查看配置可以看一些文件節點的配置信息: ls -Z

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章