try {
ConnectivityManager connectivityManager = (ConnectivityManager) appContext.getSystemService(Context.CONNECTIVITY_SERVICE);
Method iMthd = ConnectivityManager.class.getDeclaredMethod(
"setMobileDataEnabled", boolean.class);
if (iMthd != null) {
iMthd.setAccessible(false);
iMthd.invoke(connectivityManager, enable);
}
} catch (Exception e) {
e.printStackTrace();
}
Upto kitkat 以上机制工作正常,但在棒棒糖中没有解决是否有任何其他方法可以实现这一点。