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

大兔子大兔子 提交于 2019-12-02 01:21:34
bbodenmiller

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

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);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!