Wi-Fi Direct
来自官网:
Android now supports Wi-Fi Direct for peer-to-peer (P2P) connections between Android-powered devices and other device types without a hotspot or Internet connection. The Android framework provides a set of Wi-Fi P2P APIs that allow you to discover and connect to other devices when each device supports Wi-Fi Direct, then communicate over a speedy connection across distances much longer than a Bluetooth connection.
英文不大好,大意是android 4.0 提供了点对点共享上网的api,换而言之。程序员可以通过该api实现支持 Wifi Driect的设备进行网络共享。(注: 现在市场上部分手机支持移动AP功能,即无限路由器与p2p 有区别)
看看怎样提供这些功能:
来自官网:
A new package, android.net.wifi.p2p, contains all the APIs for performing peer-to-peer connections with Wi-Fi. The primary class you need to work with isWifiP2pManager, which you can acquire by calling getSystemService(WIFI_P2P_SERVICE). The WifiP2pManager 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 receive callbacks when an operation such as discovering peers or connecting to them succeeds or fails. -
WifiP2pManager.PeerListListenerinterface allows you to receive information about discovered peers. The callback provides aWifiP2pDeviceList, from which you can retrieve aWifiP2pDeviceobject for each device within range and get information such as the device name, address, device type, the WPS configurations the device supports, and more. - The
WifiP2pManager.GroupInfoListenerinterface allows you to receive information about a P2P group. The callback provides aWifiP2pGroupobject, which provides group information such as the owner, the network name, and passphrase. -
WifiP2pManager.ConnectionInfoListenerinterface allows you to receive information about the current connection. The callback provides aWifiP2pInfoobject, which has information such as whether a group has been formed 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_STATE-
INTERNET(although your app doesn’t technically connect to the Internet, communicating to Wi-Fi Direct peers with standard java sockets requires Internet permission).
-
WIFI_P2P_CONNECTION_CHANGED_ACTION: The P2P connection state has changed. This carriesEXTRA_WIFI_P2P_INFOwith aWifiP2pInfoobject andEXTRA_NETWORK_INFOwith aNetworkInfoobject. -
WIFI_P2P_STATE_CHANGED_ACTION: The P2P state has changed between enabled and disabled. It carriesEXTRA_WIFI_STATEwith eitherWIFI_P2P_STATE_DISABLEDorWIFI_P2P_STATE_ENABLED -
WIFI_P2P_PEERS_CHANGED_ACTION: The list of peer devices has changed. -
WIFI_P2P_THIS_DEVICE_CHANGED_ACTION: The details for this device have changed.
详细指导怎么用:
可以参考文档和demo。
See the WifiP2pManager documentation for more information. Also look at the Wi-Fi Direct Demo sample application.
最后附一些大能如何使用WIFI P2P:
andoird wifi 点对点连接笔记本的ad-hoc:http://www.tourgz.com/bbs/thread-1183-1-1.html
转载请注明出处,谢谢!
本文详细介绍了如何在 Android 设备上利用 Wi-Fi Direct API 实现点对点网络共享功能,包括初始化、发现设备、建立连接等步骤,并强调了所需权限和广播事件的重要性。

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



