2015-11-05 87 views
1

我正在創建一個需要更改數據連接的應用程序。 我發現了一個解決方案:使用su命令,但問題是每次執行命令時都會顯示Toast Warning。 是否可以使用這些命令而不用吐司警告?

是否有方法使用反射切換與TelephonyManager啓用的數據連接?我試過了,但沒有奏效。Android Lollipop中有可能打開/關閉數據連接?

我的代碼如下:

public static void setMobileDataState(boolean mMobileDataEnabled){ 

    try{ 
     if(mMobileDataEnabled) 
      Shell.runAsRoot(new String[]{"svc data enable"}); 
     else 
      Shell.runAsRoot(new String[]{"svc data disable"}); 
    } 
    catch (Exception ex){ 
     Utilities.log(ex.toString()); 
    } 

} 



public class Shell { 

public static void runAsRoot(String[] mCommands){ 

    try { 
     Process mProcess = Runtime.getRuntime().exec("su"); 
     DataOutputStream mOS = new DataOutputStream(mProcess.getOutputStream()); 
     for (String mCommand : mCommands) { 
      mOS.writeBytes(mCommand + "\n"); 
     } 
     mOS.writeBytes("exit\n"); 
     mOS.flush(); 

    }catch (Exception o){ 
     Utilities.log(o.toString()); 
    } 

} 
} 

回答

1

我找到了解決辦法..... 我做了以下內容:

  1. 我紮根在我的設備
  2. 我安裝我的應用程序的系統應用程序,這很簡單,只需將你的apk複製到/system/priv-app/myApk.apk並設置chmod 644權限即可。如果您有疑問,請查看此帖(If i set my android app to a system app, after a factory reset, will it be removed from the phone?)。
  3. 只是除去/系統/應用程序/ SuperSU夾
  4. 我做裝置出廠設置,那就是它..... = d