Trevor Johns | 89d2da0 | 2015-08-13 18:28:15 -0700 | [diff] [blame] | 1 | |
Renato Mangini | ebeca0e | 2014-11-11 17:55:39 -0800 | [diff] [blame] | 2 | Android MessagingService Sample |
Trevor Johns | 89d2da0 | 2015-08-13 18:28:15 -0700 | [diff] [blame] | 3 | =================================== |
Renato Mangini | ebeca0e | 2014-11-11 17:55:39 -0800 | [diff] [blame] | 4 | |
| 5 | This sample shows a simple service that sends notifications using |
| 6 | NotificationCompat. In addition to sending a notification, it also extends |
| 7 | the notification with a CarExtender to make it compatible with Android Auto. |
| 8 | Each unread conversation from a user is sent as a distinct notification. |
| 9 | |
Trevor Johns | 89d2da0 | 2015-08-13 18:28:15 -0700 | [diff] [blame] | 10 | Introduction |
| 11 | ------------ |
| 12 | |
| 13 | #### Checklist while building a messaging app that supports Android Auto: |
Nagesh Susarla | 6080e4e | 2014-11-21 14:52:27 -0800 | [diff] [blame] | 14 | 1. Ensure that Message notifications are extended using |
Renato Mangini | ebeca0e | 2014-11-11 17:55:39 -0800 | [diff] [blame] | 15 | NotificationCompat.Builder.extend(new CarExtender()...) |
Nagesh Susarla | 6080e4e | 2014-11-21 14:52:27 -0800 | [diff] [blame] | 16 | 2. Declare a meta-data tag to your AndroidManifest.xml to specify that your app |
Renato Mangini | ebeca0e | 2014-11-11 17:55:39 -0800 | [diff] [blame] | 17 | is automotive enabled. |
Nagesh Susarla | 6080e4e | 2014-11-21 14:52:27 -0800 | [diff] [blame] | 18 | |
| 19 | example: AndroidManifest.xml |
| 20 | |
Renato Mangini | ebeca0e | 2014-11-11 17:55:39 -0800 | [diff] [blame] | 21 | ``` |
| 22 | <meta-data android:name="com.google.android.gms.car.application" |
| 23 | android:resource="@xml/automotive_app_desc"/> |
| 24 | ``` |
Nagesh Susarla | 6080e4e | 2014-11-21 14:52:27 -0800 | [diff] [blame] | 25 | |
| 26 | Include the following to indicate that the application wants to show notifications on |
Renato Mangini | ebeca0e | 2014-11-11 17:55:39 -0800 | [diff] [blame] | 27 | the Android Auto overview screen. |
Nagesh Susarla | 6080e4e | 2014-11-21 14:52:27 -0800 | [diff] [blame] | 28 | |
Trevor Johns | 89d2da0 | 2015-08-13 18:28:15 -0700 | [diff] [blame] | 29 | example: res/xml/automotive\_app\_desc.xml |
Renato Mangini | ebeca0e | 2014-11-11 17:55:39 -0800 | [diff] [blame] | 30 | ``` |
Trevor Johns | 89d2da0 | 2015-08-13 18:28:15 -0700 | [diff] [blame] | 31 | <automotiveApp> |
| 32 | <uses name="notification"/> |
| 33 | </automotiveApp> |
Renato Mangini | ebeca0e | 2014-11-11 17:55:39 -0800 | [diff] [blame] | 34 | ``` |
| 35 | |
Trevor Johns | 89d2da0 | 2015-08-13 18:28:15 -0700 | [diff] [blame] | 36 | #### Flow |
Renato Mangini | ebeca0e | 2014-11-11 17:55:39 -0800 | [diff] [blame] | 37 | MessagingFragment is shown to the user. Depending on the button clicked, the MessagingService is |
Nagesh Susarla | 6080e4e | 2014-11-21 14:52:27 -0800 | [diff] [blame] | 38 | sent a message. MessagingService in turn creates notifications which can be viewed either on the |
| 39 | device or in the messaging-simulator. |
Trevor Johns | 89d2da0 | 2015-08-13 18:28:15 -0700 | [diff] [blame] | 40 | |
| 41 | When a message is read, the associated PendingIntent is triggered and MessageReadReceiver is called |
Renato Mangini | ebeca0e | 2014-11-11 17:55:39 -0800 | [diff] [blame] | 42 | with the appropriate conversationId. Similarly, when a reply is received, the MessageReplyReceiver |
| 43 | is called with the appropriate conversationId. MessageLogger logs each event and shows them in a |
| 44 | TextView in MessagingFragment for correlation. |
| 45 | |
Renato Mangini | ebeca0e | 2014-11-11 17:55:39 -0800 | [diff] [blame] | 46 | Pre-requisites |
| 47 | -------------- |
| 48 | |
Trevor Johns | 89d2da0 | 2015-08-13 18:28:15 -0700 | [diff] [blame] | 49 | - Android SDK v23 |
Trevor Johns | d8cda51 | 2015-08-14 16:18:25 -0700 | [diff] [blame] | 50 | - Android Build Tools v23.0.0 |
Renato Mangini | ebeca0e | 2014-11-11 17:55:39 -0800 | [diff] [blame] | 51 | - Android Support Repository |
| 52 | |
Trevor Johns | 89d2da0 | 2015-08-13 18:28:15 -0700 | [diff] [blame] | 53 | Screenshots |
| 54 | ------------- |
| 55 | |
| 56 | <img src="screenshots/1-main.png" height="400" alt="Screenshot"/> <img src="screenshots/2-onemessage.png" height="400" alt="Screenshot"/> <img src="screenshots/3-threemessages.png" height="400" alt="Screenshot"/> |
| 57 | |
Renato Mangini | ebeca0e | 2014-11-11 17:55:39 -0800 | [diff] [blame] | 58 | Getting Started |
| 59 | --------------- |
| 60 | |
| 61 | This sample uses the Gradle build system. To build this project, use the |
| 62 | "gradlew build" command or use "Import Project" in Android Studio. |
| 63 | |
Renato Mangini | ebeca0e | 2014-11-11 17:55:39 -0800 | [diff] [blame] | 64 | Support |
| 65 | ------- |
| 66 | |
| 67 | - Google+ Community: https://plus.google.com/communities/105153134372062985968 |
| 68 | - Stack Overflow: http://stackoverflow.com/questions/tagged/android |
| 69 | |
| 70 | If you've found an error in this sample, please file an issue: |
| 71 | https://github.com/googlesamples/android-MessagingService |
| 72 | |
| 73 | Patches are encouraged, and may be submitted by forking this project and |
| 74 | submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details. |
| 75 | |
| 76 | License |
| 77 | ------- |
| 78 | |
| 79 | Copyright 2014 The Android Open Source Project, Inc. |
| 80 | |
| 81 | Licensed to the Apache Software Foundation (ASF) under one or more contributor |
| 82 | license agreements. See the NOTICE file distributed with this work for |
| 83 | additional information regarding copyright ownership. The ASF licenses this |
| 84 | file to you under the Apache License, Version 2.0 (the "License"); you may not |
| 85 | use this file except in compliance with the License. You may obtain a copy of |
| 86 | the License at |
| 87 | |
Trevor Johns | 89d2da0 | 2015-08-13 18:28:15 -0700 | [diff] [blame] | 88 | http://www.apache.org/licenses/LICENSE-2.0 |
Renato Mangini | ebeca0e | 2014-11-11 17:55:39 -0800 | [diff] [blame] | 89 | |
| 90 | Unless required by applicable law or agreed to in writing, software |
| 91 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 92 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 93 | License for the specific language governing permissions and limitations under |
| 94 | the License. |