从此android 系统在应用中会发生很多革命性变化,代表这一个便捷通信的时代来了。。。
官方wifi-p2p :api 如下:
package
android.net.wifi.p2p
Provides classes to create peer-to-peer (P2P) connections with Wi-Fi Direct.
Using these APIs, you can discover and connect to other devices when eachdevice supports Wi-Fi Direct, then communicate over a speedy connection across distances much longerthan a Bluetooth connection. The primary class you need to work with isWifiP2pManager, which you can acquire by callinggetSystemService(WIFI_P2P_SERVICE). TheWifiP2pManager includes APIs that allow you to:
- Initialize your application for P2P connections by calling
initialize() - Discover nearby devices by calling
discoverPeers() - Start a P2P connection by calling
connect() - And more
Several other interfaces and classes are necessary as well, such as:
- The
WifiP2pManager.ActionListenerinterface allows you to receivecallbacks when an operation such as discovering peers or connecting to them succeeds or fails. WifiP2pManager.PeerListListenerinterface allows you to receiveinformation about discovered peers. The callback provides aWifiP2pDeviceList, from which you can retrieve aWifiP2pDeviceobject for each device within range and get information such asthe device name, address, device type, the WPS configurations the device supports, and more.- The
WifiP2pManager.GroupInfoListenerinterface allows you toreceive information about a P2P group. The callback provides aWifiP2pGroupobject, which provides group information such as the owner, thenetwork name, and passphrase. WifiP2pManager.ConnectionInfoListenerinterface allows you toreceive information about the current connection. The callback provides aWifiP2pInfoobject, which has information such as whether a group has beenformed and who is the group owner.
In order to use the Wi-Fi P2P APIs, your app must request the following user permissions:
ACCESS_WIFI_STATECHANGE_WIFI_STATEINTERNET(although your app doesn’t technically connectto the Internet, communicating to Wi-Fi Direct peers with standard java sockets requires Internetpermission).
For example code, see the Wi-FiDirect Demo sample application.
Note: Not all Android-powered devices support Wi-FiDirect. If your application uses Wi-Fi Direct, declare so with a<uses-feature>element in the manifest file:
<manifest ...> <uses-feature android:name="android.hardware.wifi.direct" /> ... </manifest>
Interfaces
| WifiP2pManager.ActionListener | Interface for callback invocation on an application action |
| WifiP2pManager.ChannelListener | Interface for callback invocation when framework channel is lost |
| WifiP2pManager.ConnectionInfoListener | Interface for callback invocation when connection info is available |
| WifiP2pManager.GroupInfoListener | Interface for callback invocation when group info is available |
| WifiP2pManager.PeerListListener | Interface for callback invocation when peer list is available |
Classes
| WifiP2pConfig | A class representing a Wi-Fi P2p configuration for setting up a connection |
| WifiP2pDevice | A class representing a Wi-Fi p2p device |
| WifiP2pDeviceList | A class representing a Wi-Fi P2p device list |
| WifiP2pGroup | A class representing a Wi-Fi P2p group |
| WifiP2pInfo | A class representing connection information about a Wi-Fi p2p group |
| WifiP2pManager | This class provides the API for managing Wi-Fi peer-to-peer connectivity. |
| WifiP2pManager.Channel | A channel that connects the application to the Wifi p2p framework. |
本文探讨了Android系统中p2p功能的官方支持版本如何提前出现,并带来革命性的变化,使得便捷通信成为可能。文章详细介绍了官方提供的Wi-Fi-p2p API及其相关接口和类,包括如何初始化应用、发现附近设备、建立连接等关键步骤。同时,文章强调了使用这些API所需的技术权限和功能声明,并提供了实际应用代码示例。
1364

被折叠的 条评论
为什么被折叠?



