---
title: "android wifi-director api 解读"
author: "xiaxingwork"
date: "2013-08-20T21:03:13Z"
tags: []
categories: ["移动开发"]
slug: "android-wifi-director-api"
draft: false
lastmod: "2013-08-21T11:27:33Z"
id: 1927804
url: "https://xiaxingwork.iteye.com/blog/1927804"
---

1、When a p2p connection is formed over wifi, the device continues to maintain the uplink connection over mobile or any other available network for internet connectivity on the device.

 

翻译：上边的意思是，当p2p通过wifi工作的时候，3g网络的上行和你的wifi网络该干嘛干嘛，没什么影响。不要一位p2p占用了wifi其他都得让路，wifi-director还是很强大的。

 

2、The API is asynchronous and responses to requests from an application are on listener callbacks provided by the application. 

 

翻译：p2p的api都是异步的，不要幻想你调用了某个功能立马就能生效，他会先立即返回，你调用的功能是否成功通过callback返回给你。

 

3、 For communication with legacy Wi-Fi devices that do not support p2p, an app can create a group using`createGroup(WifiP2pManager.Channel, WifiP2pManager.ActionListener)` which creates an access point whose details can be fetched with`requestGroupInfo(WifiP2pManager.Channel, WifiP2pManager.GroupInfoListener)`.

 

翻译：这个比较麻烦，搞的还不是很清楚，暂时理解成：如果设备比较老，不支持p2p，但他还是可以调用createGroup接口来启动一个热点，这个热点信息可以通过函数requestGroupInfo抓取到。

 

4、An application can advertise a Upnp or a Bonjour service with a call to `addLocalService(WifiP2pManager.Channel, WifiP2pServiceInfo, WifiP2pManager.ActionListener)`. After a local service is added, the framework automatically responds to a peer application discovering the service prior to establishing a p2p connection. A call to `removeLocalService(WifiP2pManager.Channel, WifiP2pServiceInfo, WifiP2pManager.ActionListener)` removes a local service and `clearLocalServices(WifiP2pManager.Channel, WifiP2pManager.ActionListener)` can be used to clear all local services.

 

翻译：我们可以添加一个即插即用的服务服务被添加后，framework曾可以自动优先响应服务请求。