7. Ad hoc的支持
添加ad hoc的支持有两种方式,改wpa_supplicant和改Android Framework。 改wpa_supplicant的原理和方法请参考http://www.xda-developers.com/android/android-ad-hoc-wireless-network-support/, 这种方法不推荐, 不是解决问题的根本。下面是改Android Framework的方法。
在Android Framework中添加adhoc支持很简单, 可能只需要改一行代码(当然还没经过测试), 如下:
List<ScanResult> results = mWifiManager.getScanResults(); if (results != null) { for (ScanResult result : results) { // Ignore hidden and ad-hoc networks. if (result.SSID == null || result.SSID.length() == 0 || result.capabilities.contains("[IBSS]")) { continue; }
boolean found = false; for (AccessPoint accessPoint : accessPoints) { if (accessPoint.update(result)) { found = true; } } if (!found) { accessPoints.add(new AccessPoint(this, result)); } } } |
上面一段代码在Settings应用的WifiSettings类里,发生在wpa_supplicant扫描ap结束时,将||result.capabilities.contains("[IBSS]")去掉即可支持adhoc。
可见google是故意禁了ad hoc的功能。 那么总有原因, 下面摘自某论坛:
What you say is true - it is relatively easy to support ad-hoc networks. I also appreciate that it sucks if you have to rely on ad-hoc wifi and you own an Android device.
However, there are good reasons as to why Android, or any OS for that matter, doesn't support it.
Ad-hoc networks are i