Android examples for Android OS:Root
command SU result
//package com.java2s; import android.util.Log; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; public class Main { private final static String TAG = "readwhatsapp"; public static String commandSUresult(String command) { Runtime runtime = Runtime.getRuntime(); Process proc = null;//from w ww. j av a 2 s . c om OutputStreamWriter osw = null; InputStreamReader isr = null; String ret = ""; FLOG("su " + command); try { proc = runtime.exec("su"); osw = new OutputStreamWriter(proc.getOutputStream()); osw.write(command); osw.flush(); osw.close(); char buffer[] = new char[1024]; int size = 0; isr = new InputStreamReader(proc.getInputStream()); while ((size = isr.read(buffer)) > 0) { String red = new String(buffer); ret += red; } } catch (Exception ex) { ret = ""; } finally { if (osw != null) { try { osw.close(); } catch (IOException e) { } } if (isr != null) { try { isr.close(); } catch (IOException e) { } } } try { if (proc != null) proc.waitFor(); } catch (InterruptedException e) { ret = ""; } return ret; } public static void FLOG(String s) { Log.v(TAG, s); } }