Android Runtime.getRuntime().exec


 try {  
            // Executes the command.  
            Process process = Runtime.getRuntime().exec(cmd);  
  
            // NOTE: You can write to stdin of the command using  
            // process.getOutputStream().  
            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));  
            int read;  
            char[] buffer = new char[4096];  
            StringBuffer output = new StringBuffer();  
            while ((read = reader.read(buffer)) > 0) {  
                output.append(buffer, 0, read);  
            }  
            reader.close();  
  
            // Waits for the command to finish.  
            process.waitFor();  
  
            return output.toString();  
        } catch (IOException e) {  
            throw new RuntimeException(e);  
        } catch (InterruptedException e) {  
            throw new RuntimeException(e);  
        }  
    }

 

        String mProjectName = doCommand("cat /proc/version").trim();
        Log.d(TAG, "mProjectName =" + mProjectName);


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM