在android中创buildWifi热点configuration

我正在使用android 4.1.1 …我正在制作一个应用程序,允许用户使用Wifi Hotspot制作自己的networking,然后客户端可以连接到它并共享数据。 我已经成功地在Android中创build了Wifi热点,但是我无法将其configuration为此目的。 有没有什么办法可以通过编码在android上configurationWifi Hotspot?

Solutions Collecting From Web of "在android中创buildWifi热点configuration"

这个答案可能已经过时了!

if(wifiManager.isWifiEnabled()) { wifiManager.setWifiEnabled(false); } WifiConfiguration netConfig = new WifiConfiguration(); netConfig.SSID = "MyAP"; netConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN); netConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN); netConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA); netConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); try{ Method setWifiApMethod = wifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class); boolean apstatus=(Boolean) setWifiApMethod.invoke(wifiManager, netConfig,true); Method isWifiApEnabledmethod = wifiManager.getClass().getMethod("isWifiApEnabled"); while(!(Boolean)isWifiApEnabledmethod.invoke(wifiManager)){}; Method getWifiApStateMethod = wifiManager.getClass().getMethod("getWifiApState"); int apstate=(Integer)getWifiApStateMethod.invoke(wifiManager); Method getWifiApConfigurationMethod = wifiManager.getClass().getMethod("getWifiApConfiguration"); netConfig=(WifiConfiguration)getWifiApConfigurationMethod.invoke(wifiManager); Log.e("CLIENT", "\nSSID:"+netConfig.SSID+"\nPassword:"+netConfig.preSharedKey+"\n"); } catch (Exception e) { Log.e(this.getClass().toString(), "", e); }