Android 4.0 支持wifi-p2p,从此p2p终于转正,一个便捷通信的革命来了。。

之前为了p2p应用调试而修改android 源码,业余的在Android添加了p2p功能,现在终于出现了官方支持版本,比预料中的早了很多。
从此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:

Several other interfaces and classes are necessary as well, such as:

  • The WifiP2pManager.ActionListener interface allows you to receivecallbacks when an operation such as discovering peers or connecting to them succeeds or fails.
  • WifiP2pManager.PeerListListener interface allows you to receiveinformation about discovered peers. The callback provides aWifiP2pDeviceList, from which you can retrieve aWifiP2pDevice object 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.GroupInfoListener interface allows you toreceive information about a P2P group. The callback provides aWifiP2pGroup object, which provides group information such as the owner, thenetwork name, and passphrase.
  • WifiP2pManager.ConnectionInfoListener interface allows you toreceive information about the current connection. The callback provides a WifiP2pInfo object, 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:

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.ActionListenerInterface for callback invocation on an application action  
WifiP2pManager.ChannelListenerInterface for callback invocation when framework channel is lost  
WifiP2pManager.ConnectionInfoListenerInterface for callback invocation when connection info is available  
WifiP2pManager.GroupInfoListenerInterface for callback invocation when group info is available  
WifiP2pManager.PeerListListenerInterface for callback invocation when peer list is available  

Classes

WifiP2pConfigA class representing a Wi-Fi P2p configuration for setting up a connection  
WifiP2pDeviceA class representing a Wi-Fi p2p device  
WifiP2pDeviceListA class representing a Wi-Fi P2p device list  
WifiP2pGroupA class representing a Wi-Fi P2p group  
WifiP2pInfoA class representing connection information about a Wi-Fi p2p group  
WifiP2pManagerThis class provides the API for managing Wi-Fi peer-to-peer connectivity. 
WifiP2pManager.ChannelA channel that connects the application to the Wifi p2p framework. 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值