WIFI Tether toggle

pappicio

Active Member
Licensed User
Longtime User
if you want enable/disable tether wifi, this is the solution:
B4X:
'''''Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("main") 
   Dim enabled As Boolean
   Dim r As Reflector
        r.Target = r.GetContext
        r.Target = r.RunMethod2("getSystemService", "wifi", "java.lang.String")
        enabled=r.RunMethod("isWifiApEnabled")
   If enabled=True Then 
      enabled=False
   Else
      enabled=True
   End If
   Dim r As Reflector
    r.Target = r.GetContext
    r.Target = r.RunMethod2("getSystemService", "wifi", "java.lang.String")
    r.RunMethod4("setWifiApEnabled", Array As Object(Null, enabled), _
    Array As String("android.net.wifi.WifiConfiguration", "java.lang.boolean"))
    Activity.Finish
'''''End Sub

have to add in manifest:
AddPermission(android.permission.ACCESS_WIFI_STATE)
'to give rights to see if AP is enabled
AddPermission(android.permission.CHANGE_WIFI_STATE)
'to enable/disable WIFI AP!!!

see U!
 
Top