theblixguy / ForceDoze

Enable Doze mode immediately after screen off and turn off motion sensing to get best battery life
https://play.google.com/store/apps/details?id=com.suyashsrijan.forcedoze&hl=en
GNU General Public License v3.0
178 stars 37 forks source link

Function Utils.isMobileDataEnabled(context) returns false; #50

Open slashmax opened 7 years ago

slashmax commented 7 years ago

Using Android 6.0 AOSP. From logs : wasDataTurnedOn: false;

Maybe change to something like this? :

public static bool IsMobileDataEnabled() { bool result = false;

    try
    {
        Context context = //get your context here or pass it as a param

        if (Build.VERSION.SdkInt >= BuildVersionCodes.JellyBeanMr1)
        {
            //Settings comes from the namespace Android.Provider
            result = Settings.Global.GetInt(context.ContentResolver, "mobile_data", 1) == 1;
        }
        else
        {
            result = Settings.Secure.GetInt(context.ContentResolver, "mobile_data", 1) == 1;
        }
    }
    catch (Exception ex)
    {
        //handle exception
    }

    return result;
}