在Android中创建WiFi热点配置 [英] Create Wifi Hotspot Configuration in android
本文介绍了在Android中创建WiFi热点配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我采用了android 4.1.1 ......我想提出一个应用程序,允许用户使用WiFi热点,使自己的网络,然后客户端可以连接到它和共享数据。我已经成功地创建了WiFi热点的Android,但我不能将其配置为目的。有没有什么办法可以通过编码在Android上配置的WiFi热点??
I am using android 4.1.1 ... I am making an application that allows the user to make his own network using Wifi Hotspot and then the clients can connect to it and share data. I have successfully created the Wifi hotspot in android but I cannot configure it for the purpose. Is there any way to configure Wifi Hotspot on android through coding ??
推荐答案
这个例子清楚地表明,
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);
}
这篇关于在Android中创建WiFi热点配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文