blob: e844437f94437e66b62118cba53e08012f467f31 [file] [log] [blame] [view]
Trevor Johns89d2da02015-08-13 18:28:15 -07001
Renato Manginiebeca0e2014-11-11 17:55:39 -08002Android MessagingService Sample
Trevor Johns89d2da02015-08-13 18:28:15 -07003===================================
Renato Manginiebeca0e2014-11-11 17:55:39 -08004
5This sample shows a simple service that sends notifications using
6NotificationCompat. In addition to sending a notification, it also extends
7the notification with a CarExtender to make it compatible with Android Auto.
8Each unread conversation from a user is sent as a distinct notification.
9
Trevor Johns89d2da02015-08-13 18:28:15 -070010Introduction
11------------
12
13#### Checklist while building a messaging app that supports Android Auto:
Nagesh Susarla6080e4e2014-11-21 14:52:27 -0800141. Ensure that Message notifications are extended using
Renato Manginiebeca0e2014-11-11 17:55:39 -080015NotificationCompat.Builder.extend(new CarExtender()...)
Nagesh Susarla6080e4e2014-11-21 14:52:27 -0800162. Declare a meta-data tag to your AndroidManifest.xml to specify that your app
Renato Manginiebeca0e2014-11-11 17:55:39 -080017is automotive enabled.
Nagesh Susarla6080e4e2014-11-21 14:52:27 -080018
19example: AndroidManifest.xml
20
Renato Manginiebeca0e2014-11-11 17:55:39 -080021```
22 <meta-data android:name="com.google.android.gms.car.application"
23 android:resource="@xml/automotive_app_desc"/>
24```
Nagesh Susarla6080e4e2014-11-21 14:52:27 -080025
26Include the following to indicate that the application wants to show notifications on
Renato Manginiebeca0e2014-11-11 17:55:39 -080027the Android Auto overview screen.
Nagesh Susarla6080e4e2014-11-21 14:52:27 -080028
Trevor Johns89d2da02015-08-13 18:28:15 -070029example: res/xml/automotive\_app\_desc.xml
Renato Manginiebeca0e2014-11-11 17:55:39 -080030```
Trevor Johns89d2da02015-08-13 18:28:15 -070031 <automotiveApp>
32 <uses name="notification"/>
33 </automotiveApp>
Renato Manginiebeca0e2014-11-11 17:55:39 -080034```
35
Trevor Johns89d2da02015-08-13 18:28:15 -070036#### Flow
Renato Manginiebeca0e2014-11-11 17:55:39 -080037MessagingFragment is shown to the user. Depending on the button clicked, the MessagingService is
Nagesh Susarla6080e4e2014-11-21 14:52:27 -080038sent a message. MessagingService in turn creates notifications which can be viewed either on the
39device or in the messaging-simulator.
Trevor Johns89d2da02015-08-13 18:28:15 -070040
41When a message is read, the associated PendingIntent is triggered and MessageReadReceiver is called
Renato Manginiebeca0e2014-11-11 17:55:39 -080042with the appropriate conversationId. Similarly, when a reply is received, the MessageReplyReceiver
43is called with the appropriate conversationId. MessageLogger logs each event and shows them in a
44TextView in MessagingFragment for correlation.
45
Renato Manginiebeca0e2014-11-11 17:55:39 -080046Pre-requisites
47--------------
48
Trevor Johns89d2da02015-08-13 18:28:15 -070049- Android SDK v23
Trevor Johnsd8cda512015-08-14 16:18:25 -070050- Android Build Tools v23.0.0
Renato Manginiebeca0e2014-11-11 17:55:39 -080051- Android Support Repository
52
Trevor Johns89d2da02015-08-13 18:28:15 -070053Screenshots
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 Manginiebeca0e2014-11-11 17:55:39 -080058Getting Started
59---------------
60
61This 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 Manginiebeca0e2014-11-11 17:55:39 -080064Support
65-------
66
67- Google+ Community: https://plus.google.com/communities/105153134372062985968
68- Stack Overflow: http://stackoverflow.com/questions/tagged/android
69
70If you've found an error in this sample, please file an issue:
71https://github.com/googlesamples/android-MessagingService
72
73Patches are encouraged, and may be submitted by forking this project and
74submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details.
75
76License
77-------
78
79Copyright 2014 The Android Open Source Project, Inc.
80
81Licensed to the Apache Software Foundation (ASF) under one or more contributor
82license agreements. See the NOTICE file distributed with this work for
83additional information regarding copyright ownership. The ASF licenses this
84file to you under the Apache License, Version 2.0 (the "License"); you may not
85use this file except in compliance with the License. You may obtain a copy of
86the License at
87
Trevor Johns89d2da02015-08-13 18:28:15 -070088http://www.apache.org/licenses/LICENSE-2.0
Renato Manginiebeca0e2014-11-11 17:55:39 -080089
90Unless required by applicable law or agreed to in writing, software
91distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
92WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
93License for the specific language governing permissions and limitations under
94the License.