Android L数据切换api
以下是android移动数据:Android L数据切换api,android,android-5.0-lollipop,Android,Android 5.0 Lollipop,以下是android移动数据: Method dataConnSwitchmethod; Class telephonyManagerClass; Object ITelephonyStub; Class ITelephonyClass; TelephonyManager telephonyManager = (TelephonyManager) context .getSystemService(Context.TELEPHON
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);
资料来源:
它一直工作到我的Nexus5的Android预览版!在android L或谷歌刚刚删除的api中,有没有办法切换移动数据?提前感谢。切换数据连接需要“修改手机”状态权限,该权限只能授予系统应用程序。它在4.4上运行,在android L上是否需要更多权限?您确定在4.4上使用了该权限吗?这可能是您粘贴的下面的答案,即带有ConnectionManager的答案。您粘贴的内容仅在2.2之前有效。我也在努力想办法让它在安卓L上工作。