Takeshi Hagikura | 0d83432 | 2014-09-24 18:10:45 +0900 | [diff] [blame] | 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> |
Takeshi Hagikura | f457054 | 2014-09-26 13:20:42 +0900 | [diff] [blame] | 22 | <group>Wearable</group> |
Takeshi Hagikura | dff3866 | 2014-10-31 15:52:04 +0900 | [diff] [blame] | 23 | <package>com.example.android.wearable.elizachat</package> |
Takeshi Hagikura | 0d83432 | 2014-09-24 18:10:45 +0900 | [diff] [blame] | 24 | |
Trevor Johns | 3ba022b | 2014-11-06 22:45:31 +0000 | [diff] [blame] | 25 | <minSdk>18</minSdk> |
Jeremy Walker | 9de717e | 2015-10-07 14:59:38 -0700 | [diff] [blame] | 26 | <targetSdkVersion>23</targetSdkVersion> |
Takeshi Hagikura | 0d83432 | 2014-09-24 18:10:45 +0900 | [diff] [blame] | 27 | |
Takeshi Hagikura | 0d83432 | 2014-09-24 18:10:45 +0900 | [diff] [blame] | 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"/> |
Takeshi Hagikura | 0d83432 | 2014-09-24 18:10:45 +0900 | [diff] [blame] | 40 | |
Takeshi Hagikura | a17c442 | 2014-12-04 15:59:58 +0900 | [diff] [blame] | 41 | <metadata> |
Jeremy Walker | 95207a7 | 2016-03-16 16:45:40 -0700 | [diff] [blame] | 42 | <status>DEPRECATED</status> |
Takeshi Hagikura | 8db1439 | 2014-12-05 11:51:17 +0900 | [diff] [blame] | 43 | <categories>Wearable</categories> |
Takeshi Hagikura | a17c442 | 2014-12-04 15:59:58 +0900 | [diff] [blame] | 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[ |
| 61 | A 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 | |
| 71 | This example also adds the wearable notifications as a voice input by the following code: |
| 72 | |
| 73 | ```java |
| 74 | NotificationCompat.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 | |
| 81 | Intent intent = new Intent(ACTION_RESPONSE); |
| 82 | PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, |
| 83 | PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT); |
| 84 | Notification 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(); |
| 93 | NotificationManagerCompat.from(this).notify(0, notification); |
| 94 | ``` |
| 95 | |
| 96 | When you issue this notification, users can swipe to the left to see the "Reply" action button. |
| 97 | |
| 98 | When you receive the response, you can do it by the following code: |
| 99 | |
| 100 | ```java |
| 101 | @Override |
| 102 | public 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> |
Takeshi Hagikura | 0d83432 | 2014-09-24 18:10:45 +0900 | [diff] [blame] | 126 | </sample> |