Presentation is loading. Please wait.

Presentation is loading. Please wait.

Presenter: Tyler Newsome

Similar presentations


Presentation on theme: "Presenter: Tyler Newsome"— Presentation transcript:

1 Presenter: Tyler Newsome
Android Wi-Fi P2P Presenter: Tyler Newsome

2 Overview Wi-fi P2P lets android devices communicate with other without an access point in the middle Trades cost and energy for speed and range with respect to Bluetooth Wi-Fi API consists of three components Methods that interact with or discover peers WifiP2PManager class Listeners that respond to the results of WifiP2PManager method calls Can send listeners as parameter to method calls Intents that are broadcast when certain events happen Can capture the intent and act on it

3 References Study – all code comes from one of these resources
Guides

4 What is Wi-Fi P2P? Well….what is Wi-Fi?
That thing that lets you go on the internet? Wi-Fi is a standard technology to provide wireless communication between any two conforming devices So not just for internet access, but general communication Wi-Fi P2P = direct communication between two endpoints (called peers, in our case these are phones).

5 Why use Wi-Fi P2P? Can support multiple unique apps (messaging, multiplayer games etc.) Can communicate without an intermediary access point Faster and wider range than Bluetooth At the cost of higher energy usage and cost API is relatively simple, sending and receiving messages is similar to sending/receiving requests

6 Wi-FI P2P API Consists of three components
Methods that interact with or discover peers WifiP2PManager class Asynchronous method calls Listeners that respond to the results of WifiP2PManager method calls Can send listeners as parameter to method calls Intents that are broadcast when certain events happen Can capture the intent and act on it All of these pieces are needed for most applications that need P2P. Make sure you know how to make use of all three!

7 WifiP2PManager Class Useful methods
This class contains many methods for P2P interaction Get using getSystemService(Context.WIFI_P2P_SERVICE); Useful methods initialize() – registers the application connect() – connect to another device with P2P discoverPeers() – initiates peer discovery Will broadcast a WIFI_P2P_PEERS_CHANGED_ACTION intent if peer list has changed requestPeers() – returns the current list of peers

8 Example Peer discovery Wi-Fi P2P Framework 1. discoverPeers()
2. WIFI_P2P_PEERS_CHANGED_ACTION 3. requestPeers() 4. List of Peers (Phone 2) Phone 1 Phone 2

9 Listeners and Receivers
WifiP2PManager has several listener interfaces to respond to various events You implement your own and send them as parameters to the relevant WifiP2PManager methods Also need to implement a Broadcast Receiver to capture Intents generated by the Wi-Fi P2P framework

10 Creating a Broadcast Receiver
okokok

11 Full Wi-Fi Capable App Following along withhttps://developer.android.com/guide/topics/connectivity/wifip2p.html This shows how to fully initiate and setup a Wi-Fi connection to a peer There can be a lot of moving parts but remember the three components: WifiP2PManager, Listeners, and a Broadcast Receiver

12 1. Check the minAPI level and request permissions in the android manifest file
2. Check to see if Wi-Fi is on/supported. Do this by waiting for the WIFI_P2P_STATE_CHANGED_ACTION in your Broadcast Receiver’s onReceive method

13 3. In your app’s onCreate(), get the WifiP2PManager and initialize your device and Broadcast Receiver. Note: The Receiver given here is a custom class, *not* a built in class

14 4. Setup an Intent Filter with the Intents your Broadcast Receiver needs
5. Register/unregister your receiver on resume/pause

15 6. Discover peers, using a custom ActionListener al
mManager.discoverPeers(channel, al); 7. Catch the appropriate intent with your Broadcast Listener and request the list of peers, using a custom PeerListListener

16 8. requestPeers() will produce a callback with your PeerListListener’s onPeersAvailable() method, providing a list of peers as an argument to the method. From here, you can examine the list and choose a device. In the following code, device would be a device obtained from the list.

17 9. You are now connected to a peer
9. You are now connected to a peer! All relevant information can retrieved from the peer list, and you can now use normal socket I/O to communicate between the devices. For more info It took a some work, but with this setup you can leverage all the features of sockets to communicate between devices.

18 You now know Wi-Fi P2P

19 Image References Doge - All other images not self-made are from android wifip2p tutorial


Download ppt "Presenter: Tyler Newsome"

Similar presentations


Ads by Google