【发布时间】:2011-03-17 09:24:12
【问题描述】:
我需要为 android 制作一个 aap,首先需要启用 3g 数据服务。请让我知道更改设置值的不同方法,例如。可以使用的 adb shell 命令或 API/库。示例链接会更有用。
提前致谢。
【问题讨论】:
我需要为 android 制作一个 aap,首先需要启用 3g 数据服务。请让我知道更改设置值的不同方法,例如。可以使用的 adb shell 命令或 API/库。示例链接会更有用。
提前致谢。
【问题讨论】:
感谢 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);
【讨论】: