根据Android文档,使用Wi-Fi Aware,您可以在服务发现阶段在设备之间发送数据(仅轻量级!最大255个字节),并且在需要时可以打开设备之间的连接以发送更大的数据.使用Wi-Fi对等网络时,必须先执行某种身份验证,然后再打开套接字,然后才能在设备之间发送数据.
The Wi-Fi Aware APIs let apps perform the following operations:
Discover other devices: […] After the subscriber discovers a publisher, the subscriber can either send a short message or establish a network connection with the discovered device.
Create a network connection: After two devices have discovered each other […] they can create a bi-directional Wi-Fi Aware network connection without an access point.
Note: Messages are generally used for lightweight messaging, as they might not be delivered (or be delivered out-of-order or more than once) and are limited to about 255 bytes in length.
此外,使用Wi-Fi Aware,开发人员可以在DiscoverySession类的createNetworkSpecifierOpen()方法和createNetworkSpecifierPassphrase()方法之间进行选择,以分别打开设备之间的未加密或加密连接.
使用Wi-Fi对等时,开发人员除了WifiP2PManager.connect()方法外别无选择.调用它会在所连接的设备上触发一个对话框(按钮配置),并且仅当两个设备首次相互连接时才会出现该对话框.顺便说一句…修改WifiP2pConfig的WpsInfo是没有用的.它将始终使用“按钮配置”选项.