2015-11-05 83 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