Android 4.0 亮点之WI-FI Direct

 

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:

通过WifiP2pManager,实现P2P的初始化 initialize(),使用discoverPeers() 发现可链接的设备,最后调用connect()进行握手。(这个过程应该和蓝牙链接差不多)

链接后,就可以做很多想做的事情咯。(动动脑筋开发一些有用的应用,甩信是个很好的例子)


功欲善其事,必先利其器
来自官网:

 

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

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


 

最后一些广播和事件必须通知到系统的

来自官网:

 

 

详细指导怎么用: 

可以参考文档和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

 

 

转载请注明出处,谢谢!

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值