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