Android 2.2的WiFi热点API [英] Android 2.2 wifi hotspot API

查看:230
本文介绍了Android 2.2的WiFi热点API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是API调用,我需要做的的Andr​​oid 2.2(升级Froyo)创建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).

推荐答案

您可以致电

私人布尔setWifiApEnabled(WifiConfiguration wifiConfig,布尔启用);

使用反射:)

获得后 WifiManager 使用反射来获取 WifiManager 声明的方法,寻找这个方法名 setWifiApEnabled 并通过 WifiManager 对象调用它

after getting the WifiManager use the reflection to get the WifiManager declared methods, look for this method name setWifiApEnabled and invoke it through the WifiManager object

这些API被标记为@hide,所以目前不能直接使用它们,但它们出现在AIDL的WifiManager所以他们都可以访问!

These 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!

这是示例可以是:

WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
Method[] wmMethods = wifi.getClass().getDeclaredMethods();
for(Method method: wmMethods){
  if(method.getName().equals("setWifiApEnabled")){
    WifiConfiguration netConfig = new WifiConfiguration();
    netConfig.SSID = "\"PROVAAP\"";
    netConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
    netConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
    netConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
    netConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);    netConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
    netConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
    netConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
    netConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);  

    try {
      method.invoke(wifi, netConfig,true);
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    } catch (InvocationTargetException e) {
      e.printStackTrace();
    }
  }
}

它的工作原理,但我不能用我自己的更改当前配置,并得到了积极AP当前WifiConfiguration开车带我到一个空configuration.Why?

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?

这篇关于Android 2.2的WiFi热点API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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