1<p>This is a demo application highlighting how to advertise and discover local services that are Wi-Fi peer to peer network capable with 2the Wi-Fi Direct Service Discovery APIs. Service discovery on Wi-Fi direct allows applications to discover and enagage with peers that support a certain service. 3As an example, a gaming application can find and associate with devices that support the game. This application allows you to chat with a peer after a succesful connection.</p> 4 5<p>The source code for this demo app shows how to accomplish three key things 6with Wi-Fi Direct Service Discovery APIs: Advertise services, discover services and connect to peers advertising such services</p> 7 8<p>The application includes:<p> 9<ul> <li><a 10 href="src/com/example/android/wifidirect/discovery/WiFiServiceDiscoveryActivity.html"><code>WiFiServiceDiscoveryActivity</code></a> 11 — the main <code>Activity</code> that contains two fragments to handle app's UI. It advertises and discovers services and also registers a broadcast receiver for Wi-Fi Direct related events.</li> <li><a 12 href="src/com/example/android/wifidirect/discovery/WiFiDirectBroadcastReceiver.html"><code> 13 WiFiDirectBroadcastReceiver</code></a> — a <code>BroadcastReceiver</code> 14 that listens for Wi-Fi Direct related events and passes them to 15 <code>WiFiServiceDiscoveryActivity</code> and it's fragments for neccesary action.</li> <li><a 16 href="src/com/example/android/wifidirect/discovery/WiFiDirectServicesList.html"><code>WiFiDirectServicesList</code></a> 17 — a <code>ListFragment</code> that displays available services, peers and their status. </li> 18<li><a href="src/com/example/android/wifidirect/discovery/WiFiChatFragment.html"><code>WiFiChatFragment</code></a> 19 — a <code>Fragment</code> that displays handles chat UI </li> 20<li><a href="src/com/example/android/wifidirect/discovery/ChatManager.html"><code>ChatManager</code></a> 21 — a <code>Runnable</code> that continously performs Socket I/O.</li> 22<li><a href="src/com/example/android/wifidirect/discovery/GroupOwnerSocketHandler.html"><code>GroupOwnerSocketHandler</code></a> 23 — a <code>Thread</code> that implements a server side Socket handler and spawns a client socket per connection.</li> </ul> 24<li><a href="src/com/example/android/wifidirect/discovery/ClientSocketHandler.html"><code>GroupOwnerSocketHandler</code></a> 25 — a <code>Thread</code> that implements a client side Socket handler.</li> </ul> 26<p>If you are developing an application that uses the Wi-Fi Direct Service Discovery APIs, remember that the 27feature is supported only on Android 4.1 (API level 16) and higher versions of 28the platform. To ensure that your application can only 29be installed on devices that are capable of supporting Wi-Fi Direct Service Discovery, remember to add the 30following to the application's manifest before publishing to Google Play:</p> 31<ul> <li><code><uses-sdk android:minSdkVersion="16" /></code>, which 32 indicates to Google Play and the platform that your application requires 33 Android 4.1 or higher. For more information, see <a 34 href="../../../guide/appendix/api-levels.html">API Levels</a> and the 35 documentation for the <a 36 href="../../../guide/topics/manifest/uses-sdk-element.html"><code><uses-sdk></code></a> 37 element.</li> </ul> <p>To control how Google Play filters your application 38from devices that do not support Wi-Fi Direct mode, remember to add the following to the 39application's manifest <ul> <li><code><uses-feature 40 android:name="android.hardware.wifi.direct" /></code>, which tells Google 41 Play that your application uses the Wi-Fi Direct API. The declaration should include 42 an <code>android:required</code> attribute that indicates whether you want 43 Google Play to filter the application from devices that do not offer Wi-Fi Direct support. Other <code><uses-feature></code> declarations may also be 44 needed, depending on your implementation. For more information, see the 45 documentation for the <a 46 href="../../../guide/topics/manifest/uses-feature-element.html"><code><uses-feature></code></a> 47 element.</li> </ul> 48<p>For more information about using the Wi-Fi Direct Service Discovery APIs, see the <a 49 href="../../../reference/android/net/wifi/p2p/package-summary.html"><code>android.net.wifi.p2p </a></code> 50documentation. </p> 51 52<img alt="" src="../images/WifiDirect.png" /> 53