Android Question Mobile network

jefflynn1974

Member
Licensed User
Longtime User
Is there any method to check the mobile connection (dataconnection) is enabled or not? I found a lot of ways but all of them gived back fake datas if the WiFi was ON.

Any ideas or I can't do anything with this?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use this code:
B4X:
Sub MobileDataEnabled As Boolean
   Dim r As Reflector
   r.Target = r.GetContext
   r.Target = r.RunMethod2("getSystemService", "connectivity", "java.lang.String")
   Return r.RunMethod("getMobileDataEnabled")
End Sub

Add this line to the manifest editor:
B4X:
AddPermission(android.permission.ACCESS_NETWORK_STATE)

Note that it calls a hidden API. This means that it might be removed in a future version of Android.
 
Upvote 0
Top