Can't set “WifiConfiguration” when enabling wifi-hotspot using “setWifiApEnabled”

后端 未结 2 1948
挽巷
挽巷 2021-01-21 08:19

I\'m trying to set my Android device to be an Access-Point using the code I\'ve seen here before:

WifiManager wifi = (WifiManager) getSystemService(Context.WIFI         


        
相关标签:
2条回答
  • 2021-01-21 08:29

    See how I got this working at Android 2.3 wifi hotspot API.

    0 讨论(0)
  • 2021-01-21 08:34

    Before Invoking the Method "setWifiApEnabled" you need to call "getWifiApConfiguration" to get the default WifiConfiguration
    Then change the SSID and Password and then invoke "setWifiApConfiguration" with the modified WifiConfiguration and after that call "setWifiApEnabled"
    Here is the Code.

    WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    
    getWifiConfig = wifi.getClass().getMethod("getWifiApConfiguration",null);
    WifiConfiguration myConfig = (WifiConfiguration) getWifiConfig.invoke(wifi,null);
    
    myConfig.SSID = "Hello World";
    
    setWifiConfig = wifi.getClass().getMethod("setWifiApConfiguration",WifiConfiguration.class);
    setWifiConfig.invoke(wifi,new Object[]{myConfig,true});
    
    enableWifi = wifi.getClass().getMethod("setWifiEnabled",WifiConfiguration.class,boolean.class);
    enableWifi.invoke(wifi,null,true);
    
    0 讨论(0)
提交回复
热议问题