【问题标题】:Turning mobiledata on/off in android API 17在 android API 17 中打开/关闭移动数据
【发布时间】:2016-10-31 06:42:39
【问题描述】:

API 级别 17 中使用 android adb shell 我可以使用 svc 数据启用/禁用 启用和禁用移动数据,但如果我尝试务实地进行它确实有效并且毫无例外地通过这是我的代码

    try{ Log.e(TAG,"Before mobile data thread");
    Process proc = Runtime.getRuntime().exec("su");
    DataOutputStream os= new DataOutputStream(proc.getOutputStream());
    os.writeBytes("svc data disable\n");
    os.writeBytes("exit\n");
    os.flush();
    try{
        proc.waitFor();
        if(proc.exitValue() !=255)
        {
            Log.e(TAG,"Disabling mobile data");
        }else{
            Log.e(TAG,"Error Disabling mobile data");

            }

        }catch(Exception e){}
} catch (Exception ex){Log.e(TAG,"IN mobile data exception exception");} 

任何建议我如何禁用/启用移动数据

【问题讨论】:

    标签: java android-4.2-jelly-bean


    【解决方案1】:

    如果手机未 root 或您的应用未处于设备管理员模式,您无法自行启用或禁用移动数据。您只能要求用户启用/禁用应用程序数据。

    您可以像这样在对话框中询问用户:

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Please turn on mobile data access")
        .setTitle("Unable to connect")
        .setCancelable(false)
        .setPositiveButton("Settings", (dialog, id) -> startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS)))
        .setNegativeButton("Cancel", null)
        .show()
    

    root 手机使用this answer

    【讨论】:

      猜你喜欢
      • 2018-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-20
      • 2020-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多