I would like to know if the mobile network is enabled or disabled.
My application is designed to help the user when he receives a phone call, and to do this I need I
UPDATE FOR ANDROID 5.0+ (API 21+)
Calling getMobileDataEnabled
via the reflection leads to NoSuchMethodException
on Android 5.0+ on some devices. So in addition to accepted answer you may wanna do second check if NoSuchMethodException
is thrown.
...
catch(NoSuchMethodException e)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
isDataEnabled = Settings.Global.getInt(context.getContentResolver(), "mobile_data", 0) == 1;
}
}