wifi direct

24
Speaker: 陳陳陳 Source code: https://android.googlesource.com/platfo rm/development/+/master/samples/ WiFiDirectDemo WiFi Direct

Upload: roy-chen

Post on 11-Jan-2017

70 views

Category:

Engineering


0 download

TRANSCRIPT

PowerPoint

Speaker: Source code: https://android.googlesource.com/platform/development/+/master/samples/WiFiDirectDemoWiFi Direct

OutlineDemo WiFi DirectappWiFi Directapp

IntroductionWi-FiWi-Fi DirectWi-Fi Wi-Fi Peer-to-PeerwifiAccess Point wifi Wi-FiWi-Fi Wi-Fi Direct

Bluetooth4.0

Enabled Wi-Fi Direct

Demo WiFi Direct Photo Sharing app

WifiP2pManagerTheWifiP2pManagerclass provides methods to allow you to interact with the Wi-Fi hardware on your device to do things like discover and connect to peers.

WifiP2pManager methods:initialize()connect()discoverPeers()requestPeers()

Asynchronous methods

WifiP2pManagermethods let you pass in a listener, so that the Wi-Fi P2P framework can notify your activity of the status of a call.WifiP2pManager methodslistener, manager.discoverPeers WifiP2pManager.ActionListListener.

Wifip2p events are intentsWIFI_P2P_CONNECTION_CHANGED_ACTIONWIFI_P2P_PEERS_CHANGED_ACTIONWIFI_P2P_STATE_CHANGED_ACTIONWIFI_P2P_THIS_DEVICE_CHANGED_ACTIONThe Wi-Fi P2P APIs define intents that are broadcast when certain Wi-Fi P2P events happen, such as when a new peer is discovered or when a device's Wi-Fi state changes. You can register to receive these intents in your application bycreating a broadcast receiverthat handles these intents.

intent11

Broadcast Receiver for Wi-Fi P2P Intents

A broadcast receiver allows you to receive intents broadcast by the Android system, so that your application can respond to events that you are interested in.

broadcast receiver main activity onResume CONNECTION_CHANGED intent action, , p2p (data link layer by mac addr)intent, broadcast receiver, socketTHIS_DEVICE_CHANGED STATE_CHANGED, wifi enablePEERS_CHANGED, peer listintent, requestPeers()list

12

Workflow - Broadcast Receiver

discoverPeers()

discoverPeers() ActionListener, callbackonSuccess(){} device function p2pwifi device, "WIFI_P2P_PEERS_CHANGED_ACTION" intent, BroadCast Receiverintent, !! intentp2p devicelist, intentp2p device.14

discoverPeers() & ActionListener

ActionListener,onSuccess

discoverPeers() ActionListener, callbackonSuccess(){} device function p2pwifi device, "WIFI_P2P_PEERS_CHANGED_ACTION" intent, BroadCast Receiverintent, !! intentp2p devicelist, intentp2p device.

15

requestPeers()

requestPeers() & PeerListListener

1. "WIFI_P2P_PEERS_CHANGED_ACTION" requestPeers(), p2p link list

2. requestPeers() PeerListListeneronPeersAvailablecallback functiononPeersAvailable peersList ()

3.peerList: device, devicedetail? (detaild mac address...)17

Connect()

Connect()

requestPeerspeerlist,peerconnet()mac address, connect Wifip2pCinfug, devicemac addr. onSuccess() request , WIFI_P2P_CONNECTION_CHANGED_ACTION intent, broadcast receiver

19

Socket stream

(mac addr). ,socket

2. server, client server Socket, client Socket1. devicep2pgroup,group owner,group owner,""client, server(group owner)

3. client sideWifiP2pInfo serverip, streaming.

Server socket

Client socket

References

http://chris959.blogspot.tw/2012/04/wifi-direct.html