Android Question Identifying if the "Use Wireless Networks" is enabled or not

siddsg

Member
Licensed User
Longtime User
Hello,
I need help with identifying if the "Location and Security > Use Wireless Networks" is enabled or not.

Am able to identify if GPS is enabled or not by using the following line from the GPS tutorial...

B4X:
        If GPS1.GPSEnabled = False Then
            Dim Choice As  Int
            Choice = Msgbox2("GPS is disabled. Click OK to enable", "", "OK", "Cancel","", Null)
            If Choice = DialogResponse.POSITIVE Then
                StartActivity(GPS1.LocationSettingsIntent)        'Will open the relevant settings screen.
            Else If Choice = DialogResponse.CANCEL Then
                Return False       
            End If
        Else
            GPS1.Start(0,0)                                'Listen to GPS with no filters.
        End If

Similarly, would like to identify if the Use wireless Networks option is enabled or not, for the purpose of picking location from the cell tower.

Thanks,
Siddharth
 

stevel05

Expert
Licensed User
Longtime User
You can test if the Wireless is currently enabled using the reflection library:

B4X:
Dim R As Reflector
R.Target=R.GetContext
R.Target=R.RunMethod2("getSystemService","wifi","java.lang.String")
Log(R.RunMethod("isWifiEnabled"))

returns true of false.

you need to add the permission: android.permission.ACCESS_WIFI_STATE to the manifest.

Check the documentation for more options.
 
Last edited:
Upvote 0
Top