软件申请获取root权限
申请root的工具类
//获取root权限 RootManager manager=new RootManager(); manager.upgradeRootPermission(getPackageCodePath());
public class RootManager { /** * 应用程序运行命令获取 Root权限,设备必须已破解(获得ROOT权限) * * @return 应用程序是/否获取Root权限 */ public boolean upgradeRootPermission(String pkgCodePath) { Process process = null; DataOutputStream os = null; try { String cmd="chmod 777 " + pkgCodePath; process = Runtime.getRuntime().exec("su"); //切换到root帐号 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; } }
如果,这篇博客帮您解决了问题,不妨点击一下右下角的【推荐】。如果,您希望更容易地发现我的新博客,不妨点击一下【加关注】。因为,我的热情需要您的肯定和支持!感谢您的阅读,如果文章中有错误或者您有什么好的建议,也欢迎您直接留言批评指教。Thanks,friends! |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步