Define "mobile_data" row name, where the system stores the data connection checkbox/switch's state, locally:
private static final String MOBILE_DATA = "mobile_data";
And check if the value of that row is 0
or not. If it is 0
, then the data connection is unchecked/disabled (un-ticked):
private boolean isMobileDataChecked() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
// The row has been moved to 'global' table in API level 17
return Settings.Global.getInt(getContentResolver(), MOBILE_DATA, 0) != 0;
}
try {
// It was in 'secure' table before
int enabled = Settings.Secure.getInt(getContentResolver(), MOBILE_DATA);
return enabled != 0;
} catch (SettingNotFoundException e) {
// It was in 'system' table originally, but I don't remember when that was the case.
// So, probably, you won't need all these try/catches.
// But, hey, it is better to be safe than sorry :)
return Settings.System.getInt(getContentResolver(), MOBILE_DATA, 0) != 0;
}
}