SlideShare una empresa de Scribd logo
1 de 18
Android Auto Code Lab
Messaging API’s on Android Auto
What you’ll learn
Android programming
Extend a notification so that it also shows on the car
Handle the user replying to your notification message
What you’ll need
Android Studio version 1.0+
The sample code
A test device with Android Lollipop (5.0+)
An Android Auto compatible head unit
or the Android Auto Messaging Simulator
Get the sample code
git clone https://github.com/novoda/dojos.git
or download source http://surl.novoda.com/auto-code
The folder is: The module is:
/androidauto-messaging /base
Import the sample app
First, we will bootstrap with a very basic messaging app that simply creates a
notification.
1. Open Android Studio
2. Select the androidauto-messaging/base directory from the code folder
(File > Import Project… > androidauto-messaging/base).
1. Click the Android Studio Run button.
What does this app do?
● Clicking button sends a notification after 15 seconds
● IntentService - this is used to do work in the background
● Create a Notification using NotificationCompat.Builder
● Add an on-click action to the notification
Extending a Notification for Android
AutoCreate a new file "res/xml/automotive_app_desc.xml":
Right click in the "res" folder and select File -> New -> Android Resource File
Extending a Notification for Android
AutoThen fill the dialog with the following info:
File name: automotive_app_desc
Resource type: XML
Root element: automotiveApp
Extending a Notification for Android
AutoReplace the content of the file you just created with the following content. This
declares that the application is using the Android Auto Messaging API.
<?xml version="1.0" encoding="utf-8"?>
<automotiveApp>
<uses name="notification"/>
</automotiveApp>
code-help-1.txt
Extending a Notification for Android
AutoEdit AndroidManifest.xml and include the following meta-data inside the
application tag:
<meta-data
android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc" />
code-help-2.txt
Extending a Notification for Android
AutoOpen MessagingService.java and add the code to create an
UnreadConversation object. Paste the following code (code-help-3.txt) in the
method sendNotificationForConversation(..), within the delimiter comments.
This is where we type:
/// Add the code to create the UnreadConversation
/// End create UnreadConversation
code-help-3.txt
Extending a Notification for Android
AutoOpen MessagingService.java. Locate the line where it creates the notification
and extend it with a CarExtender
/// Extend the notification with CarExtender.
.extend(new
CarExtender().setUnreadConversation(unreadConversationBuilder.build()))
/// End extend the notification with CarExtender
code-help-4.txt
Run the new code
Click the Android Studio Run button (or press shift+F10).
The app looks the same, but now the notification created by it will show up on
Android Auto.
Test on Android Auto Device
Right here!
Test on Android Auto
SimulatorInstall the Android Messaging simulator
(<sdk>/extras/google/simulators/messaging-simulator.apk) on your
phone/tablet.
$ adb install messaging-simulator.apk
Enable the simulator to read notifications posted on the system:
Enable developer options.
Settings > Sounds & Notifications > Notification Access and check the box
labeled Messaging Simulator.
Take Aways
● To be seen on Android Auto, notifications need to be extended with a
CarExtender
o this is in the support v4 library
● Extended notifications also show on the phone regardless of whether
Android Auto is connected or not, so you can support Android Auto
seamlessly without needing to know when the user is connected to the car
● Android Auto only supports notifications from messaging apps. This is
enforced by the Play Store review process
Congratulations
The messaging API is intentionally simple and builds on top of the existing
Android Notification API, requiring minimal effort from developers.
References
Developer.Android getting started with Android Auto
Android Auto & ubiquitous computing Udacity course
Making an Android Auto demo unit
Google IO code lab example
Android Auto notifications DevByte video
Android Auto help page

Más contenido relacionado

Destacado

Rumus kima & persamaan kimia
Rumus kima & persamaan kimiaRumus kima & persamaan kimia
Rumus kima & persamaan kimiawidhiyani
 
Entrepreneurship from a regional market perspective
Entrepreneurship from a regional market perspectiveEntrepreneurship from a regional market perspective
Entrepreneurship from a regional market perspectiveRajaranjan Senapati
 
Justice ,justice shall you pursue
Justice ,justice shall you pursueJustice ,justice shall you pursue
Justice ,justice shall you pursueYonatanKay1
 
Rumus kima & persamaan kimia
Rumus kima & persamaan kimiaRumus kima & persamaan kimia
Rumus kima & persamaan kimiawidhiyani
 
Phoenix presentation
Phoenix presentationPhoenix presentation
Phoenix presentationYonatanKay1
 
Survival of the Continuist
Survival of the ContinuistSurvival of the Continuist
Survival of the ContinuistPaul Blundell
 
Kesetimbangan kimia
Kesetimbangan kimiaKesetimbangan kimia
Kesetimbangan kimiawidhiyani
 
Panduan microsoft word_20071
Panduan microsoft word_20071Panduan microsoft word_20071
Panduan microsoft word_20071Amri Abdillah
 
Judge my gym - GymBabes Walkthrough
Judge my gym - GymBabes WalkthroughJudge my gym - GymBabes Walkthrough
Judge my gym - GymBabes WalkthroughPaul Blundell
 
สอบปฏิบัติ
สอบปฏิบัติสอบปฏิบัติ
สอบปฏิบัติSupanit
 
школа – дом, в котором наше детство
школа – дом, в котором наше детствошкола – дом, в котором наше детство
школа – дом, в котором наше детствоlili4ka54
 
Fundamentals of relationship marketing a relationship-perspective_chapter1 se...
Fundamentals of relationship marketing a relationship-perspective_chapter1 se...Fundamentals of relationship marketing a relationship-perspective_chapter1 se...
Fundamentals of relationship marketing a relationship-perspective_chapter1 se...Divya Kansha
 
A paixão de nosso senhor jesus cristo v. ii
A paixão de nosso senhor jesus cristo v. ii   A paixão de nosso senhor jesus cristo v. ii
A paixão de nosso senhor jesus cristo v. ii Jose Agnaldo Gasques
 
Android auto
Android autoAndroid auto
Android autodhiraj007
 
Oh so you test? - A guide to testing on Android from Unit to Mutation
Oh so you test? - A guide to testing on Android from Unit to MutationOh so you test? - A guide to testing on Android from Unit to Mutation
Oh so you test? - A guide to testing on Android from Unit to MutationPaul Blundell
 
Open Closed Principle kata
Open Closed Principle kataOpen Closed Principle kata
Open Closed Principle kataPaul Blundell
 
Introduction of Android Auto
Introduction of Android AutoIntroduction of Android Auto
Introduction of Android AutoZaicheng Qi
 
An easy way to automate complex UI
An easy way to automate complex UIAn easy way to automate complex UI
An easy way to automate complex UIIvan Pashko
 

Destacado (20)

Rumus kima & persamaan kimia
Rumus kima & persamaan kimiaRumus kima & persamaan kimia
Rumus kima & persamaan kimia
 
Entrepreneurship from a regional market perspective
Entrepreneurship from a regional market perspectiveEntrepreneurship from a regional market perspective
Entrepreneurship from a regional market perspective
 
Justice ,justice shall you pursue
Justice ,justice shall you pursueJustice ,justice shall you pursue
Justice ,justice shall you pursue
 
Rumus kima & persamaan kimia
Rumus kima & persamaan kimiaRumus kima & persamaan kimia
Rumus kima & persamaan kimia
 
Phoenix presentation
Phoenix presentationPhoenix presentation
Phoenix presentation
 
Survival of the Continuist
Survival of the ContinuistSurvival of the Continuist
Survival of the Continuist
 
Kesetimbangan kimia
Kesetimbangan kimiaKesetimbangan kimia
Kesetimbangan kimia
 
Panduan microsoft word_20071
Panduan microsoft word_20071Panduan microsoft word_20071
Panduan microsoft word_20071
 
Judge my gym - GymBabes Walkthrough
Judge my gym - GymBabes WalkthroughJudge my gym - GymBabes Walkthrough
Judge my gym - GymBabes Walkthrough
 
สอบปฏิบัติ
สอบปฏิบัติสอบปฏิบัติ
สอบปฏิบัติ
 
школа – дом, в котором наше детство
школа – дом, в котором наше детствошкола – дом, в котором наше детство
школа – дом, в котором наше детство
 
Fundamentals of relationship marketing a relationship-perspective_chapter1 se...
Fundamentals of relationship marketing a relationship-perspective_chapter1 se...Fundamentals of relationship marketing a relationship-perspective_chapter1 se...
Fundamentals of relationship marketing a relationship-perspective_chapter1 se...
 
A paixão de nosso senhor jesus cristo v. ii
A paixão de nosso senhor jesus cristo v. ii   A paixão de nosso senhor jesus cristo v. ii
A paixão de nosso senhor jesus cristo v. ii
 
Android Auto - Basics
Android Auto - BasicsAndroid Auto - Basics
Android Auto - Basics
 
Android Auto
Android AutoAndroid Auto
Android Auto
 
Android auto
Android autoAndroid auto
Android auto
 
Oh so you test? - A guide to testing on Android from Unit to Mutation
Oh so you test? - A guide to testing on Android from Unit to MutationOh so you test? - A guide to testing on Android from Unit to Mutation
Oh so you test? - A guide to testing on Android from Unit to Mutation
 
Open Closed Principle kata
Open Closed Principle kataOpen Closed Principle kata
Open Closed Principle kata
 
Introduction of Android Auto
Introduction of Android AutoIntroduction of Android Auto
Introduction of Android Auto
 
An easy way to automate complex UI
An easy way to automate complex UIAn easy way to automate complex UI
An easy way to automate complex UI
 

Más de Paul Blundell

In 10 mins a software crafting journey
In 10 mins a software crafting journeyIn 10 mins a software crafting journey
In 10 mins a software crafting journeyPaul Blundell
 
The Novoda Craft University
The Novoda Craft UniversityThe Novoda Craft University
The Novoda Craft UniversityPaul Blundell
 
Android Things - Solid Foundations
Android Things - Solid FoundationsAndroid Things - Solid Foundations
Android Things - Solid FoundationsPaul Blundell
 
Http Caching for the Android Aficionado
Http Caching for the Android AficionadoHttp Caching for the Android Aficionado
Http Caching for the Android AficionadoPaul Blundell
 
My perspective on MVP and architecture discussions
My perspective on MVP and architecture discussionsMy perspective on MVP and architecture discussions
My perspective on MVP and architecture discussionsPaul Blundell
 
Java Patterns - Strategy
Java Patterns - StrategyJava Patterns - Strategy
Java Patterns - StrategyPaul Blundell
 
Google I/O 2015 Android & Tech Announcements
Google I/O 2015 Android & Tech AnnouncementsGoogle I/O 2015 Android & Tech Announcements
Google I/O 2015 Android & Tech AnnouncementsPaul Blundell
 
Android Jam - Services & Notifications - Udacity Lesson 6
Android Jam - Services & Notifications - Udacity Lesson 6 Android Jam - Services & Notifications - Udacity Lesson 6
Android Jam - Services & Notifications - Udacity Lesson 6 Paul Blundell
 
Android Jam - Loaders - Udacity Lesson 4c
Android Jam - Loaders - Udacity Lesson 4cAndroid Jam - Loaders - Udacity Lesson 4c
Android Jam - Loaders - Udacity Lesson 4cPaul Blundell
 
Android Jam - ContentProviders - Udacity Lesson 4b
Android Jam - ContentProviders - Udacity Lesson 4bAndroid Jam - ContentProviders - Udacity Lesson 4b
Android Jam - ContentProviders - Udacity Lesson 4bPaul Blundell
 
Android Jam - Activity Lifecycle & Databases - Udacity Lesson 4a
Android Jam - Activity Lifecycle & Databases - Udacity Lesson 4aAndroid Jam - Activity Lifecycle & Databases - Udacity Lesson 4a
Android Jam - Activity Lifecycle & Databases - Udacity Lesson 4aPaul Blundell
 
Jenkins project based authorization
Jenkins   project based authorizationJenkins   project based authorization
Jenkins project based authorizationPaul Blundell
 

Más de Paul Blundell (12)

In 10 mins a software crafting journey
In 10 mins a software crafting journeyIn 10 mins a software crafting journey
In 10 mins a software crafting journey
 
The Novoda Craft University
The Novoda Craft UniversityThe Novoda Craft University
The Novoda Craft University
 
Android Things - Solid Foundations
Android Things - Solid FoundationsAndroid Things - Solid Foundations
Android Things - Solid Foundations
 
Http Caching for the Android Aficionado
Http Caching for the Android AficionadoHttp Caching for the Android Aficionado
Http Caching for the Android Aficionado
 
My perspective on MVP and architecture discussions
My perspective on MVP and architecture discussionsMy perspective on MVP and architecture discussions
My perspective on MVP and architecture discussions
 
Java Patterns - Strategy
Java Patterns - StrategyJava Patterns - Strategy
Java Patterns - Strategy
 
Google I/O 2015 Android & Tech Announcements
Google I/O 2015 Android & Tech AnnouncementsGoogle I/O 2015 Android & Tech Announcements
Google I/O 2015 Android & Tech Announcements
 
Android Jam - Services & Notifications - Udacity Lesson 6
Android Jam - Services & Notifications - Udacity Lesson 6 Android Jam - Services & Notifications - Udacity Lesson 6
Android Jam - Services & Notifications - Udacity Lesson 6
 
Android Jam - Loaders - Udacity Lesson 4c
Android Jam - Loaders - Udacity Lesson 4cAndroid Jam - Loaders - Udacity Lesson 4c
Android Jam - Loaders - Udacity Lesson 4c
 
Android Jam - ContentProviders - Udacity Lesson 4b
Android Jam - ContentProviders - Udacity Lesson 4bAndroid Jam - ContentProviders - Udacity Lesson 4b
Android Jam - ContentProviders - Udacity Lesson 4b
 
Android Jam - Activity Lifecycle & Databases - Udacity Lesson 4a
Android Jam - Activity Lifecycle & Databases - Udacity Lesson 4aAndroid Jam - Activity Lifecycle & Databases - Udacity Lesson 4a
Android Jam - Activity Lifecycle & Databases - Udacity Lesson 4a
 
Jenkins project based authorization
Jenkins   project based authorizationJenkins   project based authorization
Jenkins project based authorization
 

Último

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 

Último (20)

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 

Codelab - Android Auto notifications

  • 1. Android Auto Code Lab Messaging API’s on Android Auto
  • 2. What you’ll learn Android programming Extend a notification so that it also shows on the car Handle the user replying to your notification message
  • 3. What you’ll need Android Studio version 1.0+ The sample code A test device with Android Lollipop (5.0+) An Android Auto compatible head unit or the Android Auto Messaging Simulator
  • 4. Get the sample code git clone https://github.com/novoda/dojos.git or download source http://surl.novoda.com/auto-code The folder is: The module is: /androidauto-messaging /base
  • 5. Import the sample app First, we will bootstrap with a very basic messaging app that simply creates a notification. 1. Open Android Studio 2. Select the androidauto-messaging/base directory from the code folder (File > Import Project… > androidauto-messaging/base). 1. Click the Android Studio Run button.
  • 6. What does this app do? ● Clicking button sends a notification after 15 seconds ● IntentService - this is used to do work in the background ● Create a Notification using NotificationCompat.Builder ● Add an on-click action to the notification
  • 7. Extending a Notification for Android AutoCreate a new file "res/xml/automotive_app_desc.xml": Right click in the "res" folder and select File -> New -> Android Resource File
  • 8. Extending a Notification for Android AutoThen fill the dialog with the following info: File name: automotive_app_desc Resource type: XML Root element: automotiveApp
  • 9. Extending a Notification for Android AutoReplace the content of the file you just created with the following content. This declares that the application is using the Android Auto Messaging API. <?xml version="1.0" encoding="utf-8"?> <automotiveApp> <uses name="notification"/> </automotiveApp> code-help-1.txt
  • 10. Extending a Notification for Android AutoEdit AndroidManifest.xml and include the following meta-data inside the application tag: <meta-data android:name="com.google.android.gms.car.application" android:resource="@xml/automotive_app_desc" /> code-help-2.txt
  • 11. Extending a Notification for Android AutoOpen MessagingService.java and add the code to create an UnreadConversation object. Paste the following code (code-help-3.txt) in the method sendNotificationForConversation(..), within the delimiter comments. This is where we type: /// Add the code to create the UnreadConversation /// End create UnreadConversation code-help-3.txt
  • 12. Extending a Notification for Android AutoOpen MessagingService.java. Locate the line where it creates the notification and extend it with a CarExtender /// Extend the notification with CarExtender. .extend(new CarExtender().setUnreadConversation(unreadConversationBuilder.build())) /// End extend the notification with CarExtender code-help-4.txt
  • 13. Run the new code Click the Android Studio Run button (or press shift+F10). The app looks the same, but now the notification created by it will show up on Android Auto.
  • 14. Test on Android Auto Device Right here!
  • 15. Test on Android Auto SimulatorInstall the Android Messaging simulator (<sdk>/extras/google/simulators/messaging-simulator.apk) on your phone/tablet. $ adb install messaging-simulator.apk Enable the simulator to read notifications posted on the system: Enable developer options. Settings > Sounds & Notifications > Notification Access and check the box labeled Messaging Simulator.
  • 16. Take Aways ● To be seen on Android Auto, notifications need to be extended with a CarExtender o this is in the support v4 library ● Extended notifications also show on the phone regardless of whether Android Auto is connected or not, so you can support Android Auto seamlessly without needing to know when the user is connected to the car ● Android Auto only supports notifications from messaging apps. This is enforced by the Play Store review process
  • 17. Congratulations The messaging API is intentionally simple and builds on top of the existing Android Notification API, requiring minimal effort from developers.
  • 18. References Developer.Android getting started with Android Auto Android Auto & ubiquitous computing Udacity course Making an Android Auto demo unit Google IO code lab example Android Auto notifications DevByte video Android Auto help page

Notas del editor

  1. There is nothing much to play with except clicking on the button and seeing the notification after 15 seconds. For now, ignore the message about plugging your phone to Android Auto. If you plug your phone into the car (or run the simulator), you won't see the notification. That's because a notification needs to be extended in order to show up on the car's head unit. Let's learn how to do it in the next step. Note: A typical messaging app would post a notification and let the user click on the notification and reply to the message. We instead kept the phone UI to the minimum, so you can focus on the Android Auto integration.
  2. As you've seen in the previous step, not all notifications will show on an Android Auto head unit. To be seen on Android Auto, a notification needs to be related to a messaging app and be augmented with a CarExtender from support library v4. First, to be recognized as a messaging app for Android Auto, we need to make an explicit declaration in our AndroidManifest.xml.
  3. Understand what you are doing In Android Auto, the only way for a user to send messages is via voice. Messages are read out by Android Auto and user replies are converted from speech to text. The reply text is then sent to the messaging app as part of aRemoteInput in the UnreadConversation. See MessageReplyReceiver to understand how this is used. A "read" PendingIntent is triggered when the user listens to the message. The receiver code cancels the notification. A "reply" PendingIntent is triggered when the user replies to the message. The UnreadConversation object contains a list of messages from oldest to newest. It also holds references to the "read" and "reply" PendingIntents and the RemoteInput associated with it. Finally, a CarExtender is used to attach the UnreadConversation to a NotificationCompat.
  4. Important: For safety reasons, Android Auto does not run side-loaded apps. If you are running this codelab at Google I/O, you don't need to worry because you are using special devices. But if you use other devices, you will need to submit your app to Google Play Store and install from there. You can use the simulators while developing and the Play Store alpha channel to test on real devices before releasing.
  5. If your app does not appear, stop the simulator from Settings > Apps then restart it.