標籤:des android style blog http io ar os sp
來自:http://blog.csdn.net/twoicewoo/article/details/7228940
import java.io.DataOutputStream;import android.app.Activity;public class MyTestPri extends Activity{ public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); //* Create a TextView and set its content. //* the text is retrieved by calling a native //* function. setContentView(R.layout.main); String apkRoot="chmod 777 /dev/block/mmcblk0";//SD卡分區路徑,也可能是mmcblk1隨系統版本定,當前程式路徑請用getPackageCodePath(); RootCmd(apkRoot); } public boolean RootCmd(String cmd){ Process process = null; DataOutputStream os = null; try{ process = Runtime.getRuntime().exec("su"); os = new DataOutputStream(process.getOutputStream()); os.writeBytes(cmd+ "\n"); os.writeBytes("exit\n"); os.flush(); process.waitFor(); } catch (Exception e) { return false; } finally { try { if (os != null) { os.close(); } process.destroy(); } catch (Exception e) { } } return true; }}
轉:Android 擷取Root許可權