Android Question setMobileDataEnabled fails on Marshmallow

RichyK68

Active Member
Licensed User
Longtime User
Hi,

For several years I've been using the following code to enable/disable data on a device:

B4X:
    Try
        Dim r As Reflector
        r.Target = r.GetContext
        r.Target = r.RunMethod2("getSystemService", "connectivity", "java.lang.String")
        r.RunMethod2("setMobileDataEnabled", enabled, "java.lang.boolean")
    Catch
        Log("SetMobileDataEnabled: " & LastException.Message)
    End Try

On my new Nexus 6P phone running Marshmallow, my app has stopped working so I've debugged it and found it throws the error

SetMobileDataEnabled: java.lang.Exception: java.lang.NoSuchMethodException: setMobileDataEnabled [boolean]

Does anybody know the Marshmallow equivalent to turn data on and off?

Thanks,

Richard

ps why the hell do Google make such a breaking change?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…