Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android API call to determine user setting "Data Enabled"

My program tries to detect whether a mobile network is available at a certain location.

The issue is that when I don't have a data connection it doesn't mean the network is not there... it depends on the user preferences. There are APIs available for NetworkInfo.isAvailable(), and for user settings such as whether user is roaming and roaming is enabled or whether AirplaneMode is on.

My problem is that I can't figure out whether the user has data services disabled under Settings/WirelessNetworks/MobileNetworks.

Sounds like a trivial problem but I haven't found an API call.

like image 310
Rick Avatar asked Jul 06 '11 05:07

Rick


1 Answers

In your activity:

boolean mobileDataAllowed = Settings.Secure.getInt(getContentResolver(), "mobile_data", 1) == 1;

Source: https://github.com/yanchenko/quick-settings/blob/master/src/com/bwx/bequick/handlers/MobileDataSettingHandler2.java#L123

like image 68
bmaupin Avatar answered Oct 02 '22 05:10

bmaupin