Android Question hotspot in B4A?Is it impossible?

tuhatinhvn

Active Member
Licensed User
Longtime User
I find in forum about it but can not find
I find google this code but i dont know how to use it with reflector
B4X:
        // disable wifi 
        WifiManager wifiManager = (WifiManager) mActivity.getSystemService(Context.WIFI_SERVICE); 
        wifiManager.setWifiEnabled(false);
       
        try { 
            WifiConfiguration apConfig = new WifiConfiguration();
           
            apConfig.SSID = SSID; 
            // no password now 
            //apConfig.preSharedKey = PASSWORD; 
            // reflect 
            Method method = wifiManager.getClass().getMethod( 
                    "setWifiApEnabled", WifiConfiguration.class, Boolean.TYPE);
           
            method.invoke(wifiManager, apConfig, true); 
        } catch (Exception e) { 
            e.printStackTrace(); 
        } 
        if (LOGD_ENABLED) Log.d(LOG_TAG,"Create hotspot thread end" );
    }
 

tuhatinhvn

Active Member
Licensed User
Longtime User
i saw it but can not convert this code to reflector of B4A

can you help me? thank you @Erel

B4X:
        try {
            WifiConfiguration apConfig = new WifiConfiguration();
         
            apConfig.SSID = SSID;
            // no password now
            //apConfig.preSharedKey = PASSWORD;
            // reflect
            Method method = wifiManager.getClass().getMethod(
                    "setWifiApEnabled", WifiConfiguration.class, Boolean.TYPE);
         
            method.invoke(wifiManager, apConfig, true);
 } catch (Exception e) { 
 e.printStackTrace(); 
 } if (LOGD_ENABLED) Log.d(LOG_TAG,"Create hotspot thread end" );
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Sub SetWifiApEnabled(Enabled As Boolean)
  Dim r As Reflector
  r.Target = r.GetContext
  r.Target = r.RunMethod2("getSystemService", "wifi", "java.lang.String")
  Dim wc As JavaObject
  wc.InitializeNewInstance("android.net.wifi.WifiConfiguration", Null)
  wc.SetField("SSID", <ssid>)
  r.RunMethod4("setWifiApEnabled", Array As Object(wc, Enabled), _
  Array As String("android.net.wifi.WifiConfiguration", "java.lang.boolean"))
End Sub
 
Upvote 0
Top