如何启用/ Android中禁用3G数据服务?数据、Android

由网友(轻歌.)分享简介:可能重复:结果  如何在Android上禁用移动数据 我需要为Android这需要首先实现3G数据服务的AAP。请让我知道更改设置值,例如不同的方式。亚行shell命令或API /库可以使用。联结到实施例将更为有用。 I need to make an aap for android which requires...

可能重复:结果  如何在Android上禁用移动数据

我需要为Android这需要首先实现3G数据服务的AAP。请让我知道更改设置值,例如不同的方式。亚行shell命令或API /库可以使用。联结到实施例将更为有用。

I need to make an aap for android which requires enabling the 3g data service at first. Please let me know different ways of changing the settings values eg. adb shell commands or APIs/library which can be used. Links to examples will be more useful.

先谢谢了。

推荐答案

由于stackoverflow.com

Thanks to stackoverflow.com

找到答案:如何在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);
阅读全文

相关推荐

最新文章