• Home
Name Date Size #Lines LOC

..--

.google/03-May-2024-1712

Application/03-May-2024-898496

gradle/wrapper/03-May-2024-76

screenshots/03-May-2024-

CONTRIB.mdD03-May-20241.6 KiB3627

CONTRIBUTING.mdD03-May-20241.5 KiB3627

LICENSED03-May-202411.1 KiB202169

NOTICED03-May-2024613 1611

README.mdD03-May-20244.5 KiB11589

build.gradleD03-May-202414 150

gradlewD03-May-20245 KiB165122

gradlew.batD03-May-20242.3 KiB9166

settings.gradleD03-May-202434 21

README.md

1Android ElizaChat Sample
2===================================
3
4A basic sample showing how to add extensions to notifications on wearable using
5[NotificationCompat.WearableExtender][1] API by providing a chat experience.
6
7Introduction
8------------
9
10[NotificationCompat.WearableExtender][1] API offers you a functionality to
11 add wearable extensions to notifications like [Add the Voice Input as a Notification Action][2].
12
13This example also adds the wearable notifications as a voice input by the following code:
14
15```java
16NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
17        .setContentTitle(getString(R.string.eliza))
18        .setContentText(mLastResponse)
19        .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.bg_eliza))
20        .setSmallIcon(R.drawable.bg_eliza)
21        .setPriority(NotificationCompat.PRIORITY_MIN);
22
23Intent intent = new Intent(ACTION_RESPONSE);
24PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent,
25        PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT);
26Notification notification = builder
27        .extend(new NotificationCompat.WearableExtender()
28                .addAction(new NotificationCompat.Action.Builder(
29                        R.drawable.ic_full_reply, getString(R.string.reply), pendingIntent)
30                        .addRemoteInput(new RemoteInput.Builder(EXTRA_REPLY)
31                                .setLabel(getString(R.string.reply))
32                                .build())
33                        .build()))
34        .build();
35NotificationManagerCompat.from(this).notify(0, notification);
36```
37
38When you issue this notification, users can swipe to the left to see the "Reply" action button.
39
40When you receive the response, you can do it by the following code:
41
42```java
43@Override
44public int onStartCommand(Intent intent, int flags, int startId) {
45    if (null == intent || null == intent.getAction()) {
46        return Service.START_STICKY;
47    }
48    String action = intent.getAction();
49    if (action.equals(ACTION_RESPONSE)) {
50        Bundle remoteInputResults = RemoteInput.getResultsFromIntent(intent);
51        CharSequence replyMessage = "";
52        if (remoteInputResults != null) {
53            replyMessage = remoteInputResults.getCharSequence(EXTRA_REPLY);
54        }
55        processIncoming(replyMessage.toString());
56    } else if (action.equals(MainActivity.ACTION_GET_CONVERSATION)) {
57        broadcastMessage(mCompleteConversation.toString());
58    }
59    return Service.START_STICKY;
60}
61```
62
63[1]: https://developer.android.com/reference/android/support/v4/app/NotificationCompat.WearableExtender.html
64[2]: https://developer.android.com/training/wearables/notifications/voice-input.html#AddAction
65
66Pre-requisites
67--------------
68
69- Android SDK v21
70- Android Build Tools v21.1.1
71- Android Support Repository
72
73Screenshots
74-------------
75
76<img src="screenshots/companion_eliza_chat_response.png" height="400" alt="Screenshot"/> <img src="screenshots/companion_eliza_chat.png" height="400" alt="Screenshot"/> <img src="screenshots/wearable_eliza_notification.png" height="400" alt="Screenshot"/> <img src="screenshots/wearable_voice_reply.png" height="400" alt="Screenshot"/>
77
78Getting Started
79---------------
80
81This sample uses the Gradle build system. To build this project, use the
82"gradlew build" command or use "Import Project" in Android Studio.
83
84Support
85-------
86
87- Google+ Community: https://plus.google.com/communities/105153134372062985968
88- Stack Overflow: http://stackoverflow.com/questions/tagged/android
89
90If you've found an error in this sample, please file an issue:
91https://github.com/googlesamples/android-ElizaChat
92
93Patches are encouraged, and may be submitted by forking this project and
94submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details.
95
96License
97-------
98
99Copyright 2014 The Android Open Source Project, Inc.
100
101Licensed to the Apache Software Foundation (ASF) under one or more contributor
102license agreements.  See the NOTICE file distributed with this work for
103additional information regarding copyright ownership.  The ASF licenses this
104file to you under the Apache License, Version 2.0 (the "License"); you may not
105use this file except in compliance with the License.  You may obtain a copy of
106the License at
107
108http://www.apache.org/licenses/LICENSE-2.0
109
110Unless required by applicable law or agreed to in writing, software
111distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
112WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
113License for the specific language governing permissions and limitations under
114the License.
115