1 public boolean getRootPermission(String pkgCodePath) { 2 Log.d(TAG, "pkgCodePath=" + pkgCodePath); 3 Process process = null; 4 DataOutputStream os = null; 5 try { 6 String cmd = "chmod 777 " + pkgCodePath; 7 process = Runtime.getRuntime().exec("su"); //切换到root帐号 8 os = new DataOutputStream(process.getOutputStream()); 9 os.writeBytes(cmd + "\n"); 10 os.writeBytes("exit\n"); 11 os.flush(); 12 process.waitFor(); 13 } catch (Exception e) { 14 Toast.makeText(this, "root error!" + pkgCodePath, Toast.LENGTH_SHORT).show(); 15 e.printStackTrace(); 16 return false; 17 } finally { 18 try { 19 if (os != null) { 20 os.close(); 21 } 22 process.destroy(); 23 24 25 } catch (Exception e) { 26 } 27 } 28 Toast.makeText(this, "root success!" + pkgCodePath, Toast.LENGTH_SHORT).show(); 29 return true; 30 }
getRootPermission
然后在 想申请root的地方 执行方法
getRootPermission(getPackageCodePath()); 静默安装 卸载 参考 http://www.2cto.com/kf/201503/381170.htmlhttp://ju.outofmemory.cn/entry/108796
时间: 2024-11-05 22:05:49