有没有办法在拥有Lollipop或更高版本(代码中)的Android上禁用/启用数据连接?
答案 0 :(得分:0)
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= 21) {
// Do what u want (eneble or disaqble) eg. u want to enable in this condition
Method dataMtd = ConnectivityManager.class.getDeclaredMethod("setMobileDataEnabled", boolean.class);
dataMtd.setAccessible(true);
dataMtd.invoke(connectivityManager, true);
} else {
// Do what u want (eneble or disaqble) eg. u want to disable here
Method dataMtd = ConnectivityManager.class.getDeclaredMethod("setMobileDataEnabled", boolean.class);
dataMtd.setAccessible(false);
dataMtd.invoke(connectivityManager, false);
}