Android 2.2 wifi热点API
我需要在 Android 2.2 (Froyo) 中进行什么 API 调用来创建 Wifi 热点(如网络共享和便携式热点设置项中所示)。
What is the API call I need to make in Android 2.2 (Froyo) to create a Wifi hotspot (as seen in the Tethering and Portable Hotspot settings item).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在获取
WifiManager
后使用反射调用private boolean setWifiApEnabled(WifiConfiguration wifiConfig, booleanenabled);
:) 使用
反射获取
WifiManager
声明的方法,查找这个方法名setWifiApEnabled
并通过WifiManager
对象调用它。这些API被标记为@hide,所以目前你不能直接使用它们,但它们出现在WifiManager 的 AIDL,以便可以访问它们!
一个例子是:
它可以工作,但我无法用自己的配置更改当前配置,并且获取活动 AP 的当前 WifiConfiguration 会将我带到空配置。为什么?
You can call
private boolean setWifiApEnabled(WifiConfiguration wifiConfig, boolean enabled);
using reflection :)
after getting the
WifiManager
use the reflection to get theWifiManager
declared methods, look for this method namesetWifiApEnabled
and invoke it through theWifiManager
objectThese API are marked as @hide, so currently you cannot use them directly, but they appear on the AIDL for the WifiManager so their are accessible!
An example can be:
It works but I cannot change the current configuration with my own, and getting the current WifiConfiguration of an active AP drive me to an empty configuration.Why?
这适用于 API 8 及更高版本。我使用的版本与下面(或上面)的版本截然不同,并且遇到了与 markov00 遇到的相同问题;无法加载便携式 Wi-Fi AP 的默认 WifiConfiguration。我在其他地方找到了解决方案。
如果您喜欢这个解决方案,如果它被接受作为答案,那就太好了
this works on API 8 and above. I use a heavily different version then this below (or above), and was running into the same issue markov00 ran into; not being able to load the default WifiConfiguration for the portable Wi-Fi AP. I found a solution elsewhere.
If you like the solution, it would be nice if this was accepted as an answer
似乎没有 API 调用来创建 WiFi 热点 - 抱歉!
There does not appear to be an API call to create a WiFi hotspot -- sorry!