1<?xml version="1.0" encoding="UTF-8"?>
2<!--
3 Copyright 2013 The Android Open Source Project
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9     http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16-->
17
18
19
20<sample>
21    <name>ElizaChat</name>
22    <group>Wearable</group>
23    <package>com.example.android.wearable.elizachat</package>
24
25    <minSdk>18</minSdk>
26    <targetSdkVersion>23</targetSdkVersion>
27
28    <strings>
29        <intro>
30            <![CDATA[
31            This sample is a phone application that provides a chat experience in which users can respond to
32            messages with a quick voice response. New messages create a notification with a "Reply" action.
33            The notification is bridged from phone to wearable, and selecting the "Reply" action on the
34            wearable opens the voice transcription UI allowing the user to speak a response.
35            ]]>
36        </intro>
37    </strings>
38
39    <template src="base"/>
40
41    <metadata>
42        <status>DEPRECATED</status>
43        <categories>Wearable</categories>
44        <technologies>Android</technologies>
45        <languages>Java</languages>
46        <solutions>Mobile</solutions>
47        <level>INTERMEDIATE</level>
48        <icon>screenshots/wearable_eliza_notification.png</icon>
49        <screenshots>
50            <img>screenshots/companion_eliza_chat_response.png</img>
51            <img>screenshots/companion_eliza_chat.png</img>
52            <img>screenshots/wearable_eliza_notification.png</img>
53            <img>screenshots/wearable_voice_reply.png</img>
54        </screenshots>
55        <api_refs>
56            <android>android.support.v4.app.NotificationCompat.WearableExtender</android>
57        </api_refs>
58
59        <description>
60<![CDATA[
61A basic sample showing how to add extensions to notifications on wearable using
62[NotificationCompat.WearableExtender][1] API by providing a chat experience.
63]]>
64        </description>
65
66        <intro>
67<![CDATA[
68[NotificationCompat.WearableExtender][1] API offers you a functionality to
69 add wearable extensions to notifications like [Add the Voice Input as a Notification Action][2].
70
71This example also adds the wearable notifications as a voice input by the following code:
72
73```java
74NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
75        .setContentTitle(getString(R.string.eliza))
76        .setContentText(mLastResponse)
77        .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.bg_eliza))
78        .setSmallIcon(R.drawable.bg_eliza)
79        .setPriority(NotificationCompat.PRIORITY_MIN);
80
81Intent intent = new Intent(ACTION_RESPONSE);
82PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent,
83        PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT);
84Notification notification = builder
85        .extend(new NotificationCompat.WearableExtender()
86                .addAction(new NotificationCompat.Action.Builder(
87                        R.drawable.ic_full_reply, getString(R.string.reply), pendingIntent)
88                        .addRemoteInput(new RemoteInput.Builder(EXTRA_REPLY)
89                                .setLabel(getString(R.string.reply))
90                                .build())
91                        .build()))
92        .build();
93NotificationManagerCompat.from(this).notify(0, notification);
94```
95
96When you issue this notification, users can swipe to the left to see the "Reply" action button.
97
98When you receive the response, you can do it by the following code:
99
100```java
101@Override
102public int onStartCommand(Intent intent, int flags, int startId) {
103    if (null == intent || null == intent.getAction()) {
104        return Service.START_STICKY;
105    }
106    String action = intent.getAction();
107    if (action.equals(ACTION_RESPONSE)) {
108        Bundle remoteInputResults = RemoteInput.getResultsFromIntent(intent);
109        CharSequence replyMessage = "";
110        if (remoteInputResults != null) {
111            replyMessage = remoteInputResults.getCharSequence(EXTRA_REPLY);
112        }
113        processIncoming(replyMessage.toString());
114    } else if (action.equals(MainActivity.ACTION_GET_CONVERSATION)) {
115        broadcastMessage(mCompleteConversation.toString());
116    }
117    return Service.START_STICKY;
118}
119```
120
121[1]: https://developer.android.com/reference/android/support/v4/app/NotificationCompat.WearableExtender.html
122[2]: https://developer.android.com/training/wearables/notifications/voice-input.html#AddAction
123]]>
124        </intro>
125    </metadata>
126</sample>
127