admin管理员组

文章数量:1609986

手上的小米平板1,更新到MIUI 9.6.24后,用Root刷机精灵给root了。地铁上看书时,不看了直接关机。MIUI之前有关机、重启的桌面小工具,可是升级了之后就没有了。于是我想自己实现一个。

在网上看了一阵代码后,之前有一种基于/system/xbin/ru来实现的,可是通过RE管理器,看到xbin下面没有ru。试了如下的方法之后:

关机:

public static int shutdown() { 
       int r = 0; 
       try { 
           Process process = Runtime.getRuntime().exec(new String[]{"su" , "-c" ,"reboot -p"}); 
           r = process.waitFor(); 
           java.lang.System.out.println("r:" + r ); 
       } catch (IOException e) { 
           e.printStackTrace(); 
           r = -1; 
       } catch (InterruptedException e) { 
           e.printStackTrace(); 
           r = -1; 
       } 
       return r; 
   }

reboot重启的代码:

public static int reboot() { 
       int r = 0; 
       try { 
           Process process = Runtime.getRuntime().exec("su -c reboot"); 
           r = process.waitFor(); 
           java.lang.System.out.println("r:" + r ); 
       } catch (IOException e) { 
           e.printStackTrace(); 
           r = -1; 
       } catch (InterruptedException e) { 
           e.printStackTrace(); 
           r = -1; 
       } 
       return r; 
   }

重启;(重启代码上下都可以用)

    //重启手机
                try {
                    Log.v(TAG, "root Runtime->reboot");
                    Process proc = Runtime.getRuntime().exec(new String[]{"su", "-c", "reboot "});
                    proc.waitFor();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }

 

 

本文标签: 重启方法手机androidroot