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