Java tutorial
//package com.java2s; import android.content.Context; import java.io.DataOutputStream; public class Main { public static boolean getRootPermission(Context context) { String packageCodePath = context.getPackageCodePath(); Process process = null; DataOutputStream os = null; try { String cmd = "chmod 777 " + packageCodePath; 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) { e.printStackTrace(); } } return true; } }