시스템이 로컬 데이터 연결 확인란/스위치의 상태를 저장합니다 "mobile_data"행 이름, 정의 :
private static final String MOBILE_DATA = "mobile_data";
을 그리고 그 행의 값이 0
인지 아닌지 확인한다. 0
인 경우 데이터 연결이 선택 취소/사용 중지되었습니다 (선택 안함) :
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;
}
}