如何启用/ Android中禁用3G数据服务? [英] How to enable/disable 3g data service in Android?

查看:133
本文介绍了如何启用/ Android中禁用3G数据服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  如何在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);

这篇关于如何启用/ Android中禁用3G数据服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆