不能设置与QUOT; WifiConfiguration"启用WiFi的热点时,使用" setWifiApEnabled" [英] Can't set "WifiConfiguration" when enabling wifi-hotspot using "setWifiApEnabled"

查看:273
本文介绍了不能设置与QUOT; WifiConfiguration"启用WiFi的热点时,使用" setWifiApEnabled"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图把我的Andr​​oid设备使用code我在这里看到的是一个接入点前:

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_SERVICE);

WifiConfiguration netConfig = new WifiConfiguration();
netConfig.SSID = "MyAccessPoint";

Method method = wifi.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class);
method.invoke(wifi, netConfig, true);

现在,我设法在转动,但没有它,我在WifiConfiguration设置SSID。

now, I managed to turning it on but without the SSID which I set in WifiConfiguration.

这是推动我疯了。

有人吗?

推荐答案

在调用方法setWifiApEnabled你需要调用getWifiApConfiguration获取默认WifiConfiguration
然后,更改SSID和密码,然后调用setWifiApConfiguration与修改后的WifiConfiguration和调用后setWifiApEnabled
这里是code。

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);

这篇关于不能设置与QUOT; WifiConfiguration"启用WiFi的热点时,使用" setWifiApEnabled"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆