【问题标题】:How to enable/disable 3g data service in Android? [duplicate]如何在 Android 中启用/禁用 3g 数据服务? [复制]
【发布时间】:2011-03-17 09:24:12
【问题描述】:

可能重复:
How to disable Mobile Data on Android

我需要为 android 制作一个 aap,首先需要启用 3g 数据服务。请让我知道更改设置值的不同方法,例如。可以使用的 adb shell 命令或 API/库。示例链接会更有用。

提前致谢。

【问题讨论】:

    标签: android settings


    【解决方案1】:

    感谢 stackoverflow.com

    找到答案:How to disable Mobile Data on Android

    Method dataConnSwitchmethod;
    Class telephonyManagerClass;
    Object ITelephonyStub;
    Class ITelephonyClass;
    
    TelephonyManager telephonyManager = (TelephonyManager) context
            .getSystemService(Context.TELEPHONY_SERVICE);
    
    if(telephonyManager.getDataState() == TelephonyManager.DATA_CONNECTED){
        isEnabled = true;
    }else{
        isEnabled = false;  
    }   
    
    telephonyManagerClass = Class.forName(telephonyManager.getClass().getName());
    Method getITelephonyMethod = telephonyManagerClass.getDeclaredMethod("getITelephony");
    getITelephonyMethod.setAccessible(true);
    ITelephonyStub = getITelephonyMethod.invoke(telephonyManager);
    ITelephonyClass = Class.forName(ITelephonyStub.getClass().getName());
    
    if (isEnabled) {
        dataConnSwitchmethod = ITelephonyClass
                .getDeclaredMethod("disableDataConnectivity");
    } else {
        dataConnSwitchmethod = ITelephonyClass
                .getDeclaredMethod("enableDataConnectivity");   
    }
    dataConnSwitchmethod.setAccessible(true);
    dataConnSwitchmethod.invoke(ITelephonyStub);
    

    【讨论】:

      猜你喜欢
      • 2011-09-04
      • 2013-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-12
      • 2013-03-03
      • 2012-09-07
      相关资源
      最近更新 更多