I want to disable data connection and I am using this code.
ConnectivityManager dataManager;
dataManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
try {
dataMtd = ConnectivityManager.class.getDeclaredMethod("setMobileDataEnabled", boolean.class);
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
dataMtd.setAccessible(true);
try {
dataMtd.invoke(dataManager, false);
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this will not work in dual sim. so can someone help me. how can I disable data connection in dual sim android phone? and how can i check if phone is dual sim or not
Some things to mention here:
setMobileNetworkfromLollipop
checks whether target is 5 or 5.1+, and in case of 5.1+ it loops through all subscription id's (=sim cards) to switch data services. You could combine it with your code to target previous versions as well. The downside: it requires root access, and dual-sim functionality is limited to 5.1+.