# The car is your canvas: Unlocking Android development for the road
- Speakers: Paul Lammertsma (Developer Relations Engineer), Thomas Weathers (Developer Relations Engineer)
- Track: Apps foundation
- Video: https://www.youtube.com/watch?v=8YkU3aPbQYA
- Page: https://developer.android.com/events/dev-summit/talks/the-car-is-your-canvas-unlocking-android-development-for-the-road
## About the talk
As in-car displays expand across Android Auto and Android Automotive OS vehicles, developers face a unique dual challenge: delivering rich, adaptive experiences while parked, and driver-safe, template-driven experiences while driving. In this comprehensive 30-minute technical session, we explore the end-to-end architecture and development approaches to adapting Android apps to cars.
From the fundamentals of designing apps for use in cars, to the newest approaches for building media experiences that shift from audio to video as the car shifts from drive to park, you'll leave with everything you need to know to get your app on the road.
## Summary
- Android for Cars targets two platforms: Android Auto and Android Automotive OS. One projects from a phone, while the other runs directly on the vehicle.
- The Car App Library provides templates for driving-optimized interfaces that adapt to various car hardware configurations.
- Parked car apps rely on standard Android activities for rich experiences like video streaming, games, and web browsers.
- Car App Library 1.9 brings new UI components and brand customization tokens. It also expands media template support fully to Android Automotive OS.
- Park-to-drive capabilities dynamically launch native video activities when parked, then switch back to media templates to maintain uninterrupted audio when driving.
## Resources
- [Android CLI](https://goo.gle/android-cli)
- [Android for Cars documentation](https://goo.gle/android-cars)
- [Build games for cars guide](https://goo.gle/games-in-cars)
- [What's new in Android for Cars](https://d.android.com/training/cars/whats-new)
## Topics
android-for-cars, android-auto, android-automotive-os, car-app-library, media3, parked-apps
## Transcript
### Introduction to Android for cars
[00:06](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=6s) All right.
[00:06](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=6s) Welcome, everybody.
[00:07](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=7s) Thank you for joining us in this session, The car is your canvas.
[00:11](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=11s) This session is about unlocking Android development for the road.
[00:14](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=14s) I'm Paul Lammertsma.
[00:15](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=15s) And I'm Thomas Weathers.
[00:17](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=17s) We're developer relations engineers on the Android for Cars team.
[00:21](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=21s) I'm sure many of you have spent a lot of time and energy to make sure your apps look great and function beautifully across a wide variety of different screens and devices, phones and foldables and tablets and what have you.
[00:33](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=33s) Today, we're going to be focusing on a screen that you might not have thought about.
[00:37](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=37s) And it can help you reach your users in a unique way.
[00:41](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=41s) That's the in-car display.
[00:44](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=44s) So, let's get started with a brief overview of what I mean when we talk about Android for Cars.
[00:49](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=49s) Android for Cars isn't one monolithic thing.
[00:52](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=52s) There are two platforms that you can target.
[00:54](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=54s) First, there's Android Auto, which is a phone-powered, projected system.
[00:59](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=59s) With Android Auto, the app executes on your phone and projects its UI to the in-car display using either a wired or wireless connection.
[01:08](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=68s) And second, there's Android Automotive OS, and this is a variant of Android that runs directly on the vehicle itself.
[01:14](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=74s) Android Automotive OS runs independently of the phone, has direct access to vehicle hardware, things like climate control and the radio, and, importantly, it also manages its own data connection.
[01:26](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=86s) A subset of cars running Android Automotive OS are cars with Google built-in.
[01:31](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=91s) Cars with Google built-in also come with Google apps and services, such as the Play Store, Gemini, and Google Maps.
[01:40](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=100s) While there are two platforms, our goal is to make it easy for you to build once and be able to deploy apps that provide great experiences on both platforms.
[01:50](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=110s) Now here's an example of some of a media app built once using the Car App Library, and what it would look like both on Android Auto and on Android Automotive OS, on a range of different display sizes and shapes.
[02:07](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=127s) There are many different types of devices and surfaces that you could be building for.
[02:11](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=131s) So, this begs the question, why then for cars?
[02:14](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=134s) Well, first, the scale here is pretty darn huge.
[02:17](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=137s) There are over 250 million Android Auto-compatible cars on the road today and over 100 models of cars with Google built-in across 16 different brands.
[02:29](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=149s) And when your apps are in cars, you're reaching users on their daily commutes, to and from family activities, doing errands, and even on road trips.
[02:38](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=158s) In the US, according to the 2024 American Driving Survey from the AAA, drivers spend an average of 60 minutes per day behind the wheel.
[02:49](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=169s) But you're not just reaching users while they're actively driving.
[02:52](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=172s) You're also reaching them when they're parked.
[02:54](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=174s) Think maybe they're charging their vehicle at the EV charging station, or maybe they're in line at the school pick-up line.
[03:02](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=182s) And with the rise of passenger-specific displays, we expect to see even more opportunities in the future to drive engagement with users.
[03:10](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=190s) All right.
[03:10](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=190s) Now let's look at the different type of experiences that you can build for cars.
[03:14](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=194s) To understand how to build for cars, it's helpful to understand the two main situations and states that exist for apps when they're running inside a vehicle.
[03:24](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=204s) First, there are apps that you use while driving.
[03:27](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=207s) These are driving-optimized experiences that can be used while the vehicle's in motion.
[03:33](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=213s) This includes apps in the categories that you see here listed up on the screen, things like audio apps, which we typically refer to as media, messaging and communication apps, navigation, and so on.
[03:44](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=224s) Driving-optimized experiences must adhere to strict distraction safeguard criteria.
[03:51](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=231s) There are special considerations to how to build a UI for an app so that it can safely used while the vehicle is in motion.
[03:59](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=239s) Now there are a couple of different ways of building driving-optimized apps.
### Overview of the car app library
[04:02](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=242s) But in this talk, specifically, we'll focus on using the Car App Library.
[04:06](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=246s) This is a set of Jetpack libraries that provide templated framework that provides driving-optimized user interfaces, while also taking care of adapting to the various hardware configurations that are present in cars.
[04:17](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=257s) So think about like input modalities, screen sizes, and aspect ratios.
[04:24](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=264s) While this isn't the only way of building driving-optimized experiences for cars, the approach that I want to focus on in this talk is building with the Android for Cars App Library.
[04:34](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=274s) We often call this CAL for short.
[04:37](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=277s) As I mentioned just a moment ago, the Car App Library is a set of libraries that help build your apps for use in vehicles.
[04:44](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=284s) It's a templated framework that provides driving-optimized user interfaces while handling the work of adapting to different hardware configurations.
[04:52](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=292s) And you can build your app and have the confidence that it will perform well on all those different variety of configurations, whether they're running Android Auto or on Android Automotive OS.
[05:04](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=304s) Apps building using CAL can rely on this host client architecture.
[05:09](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=309s) The host app, which is either Android Auto itself or the Google Automotive App Host in the case of cars with Google built-in, is the system renderer.
[05:17](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=317s) It's ultimately in control of what needs to be shown to the user on their displays.
[05:21](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=321s) So, as the app developer, you aren't ultimately drawing pixels.
[05:25](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=325s) Instead, you're feeding structured data to and its-- and the state of your data to Car App Library templates.
[05:32](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=332s) And it's this host that then takes this data, and it draws it safely, in a safety-compliant way, with a distraction-optimized layout.
[05:41](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=341s) So, then let's take a look at the classes within CAL, what you need to extend to build your app, starting with the CarAppService.
[05:53](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=353s) This is a subclass of Android service that serves as an entry point for host applications to communicate with client apps, and its purpose is to create session instances that the host then interacts with.
[06:07](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=367s) You can think of a session as an instance of a client app running on a display in the vehicle.
[06:11](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=371s) Like other Android components, it has a life cycle of its own that can be used to initialize and tear down resources used throughout the session's instance existence.
[06:20](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=380s) This is a one-to-many relationship between the CarAppService and a session.
[06:25](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=385s) So, for example, a CarAppService may have two session instances, one for a primary display, and another one for a cluster display for navigation apps that support cluster screens.
[06:37](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=397s) And here's an example of that, where a car has a primary display and a cluster display, each display is associated with a dedicated session, and this is also how you, as an app developer, can support multi-display vehicles.
[06:53](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=413s) Then within a session, screen instances are responsible for generating the user interfaces rendered by host apps.
[07:00](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=420s) These user interfaces are represented by template classes that each model a specific type of layout, and that could be, for instance, a grid, or a list.
[07:09](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=429s) So, each session manages a stack of screen instances that handle user flows throughout different parts of your application, and, as with the session, a screen has a life cycle of its own that you can hook into.
[07:23](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=443s) But just because the host is rendering your UI, and you using Car App Library templates, it doesn't mean that you're tightly constrained, or you can't customize your application.
[07:32](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=452s) There are a wealth of templates and components that you can use, and you can also mix and match to get the experience that you want.
[07:39](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=459s) There are general purpose templates, which can be used by all types of apps within the Car App Library, and there are a special purpose templates that are meant for particular app experiences, such as navigation, or point-of-interest.
[07:53](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=473s) But before going into details of building drive-optimized experiences, I want to cover the other situation where you can run applications in cars: when the car is parked.
### Developing apps for parked cars
[08:02](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=482s) There are certain categories of applications that can only be used while the vehicle is parked, and this is includes things like video apps, of course, games, and browsers.
[08:13](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=493s) But the car isn't-- when the car isn't in motion, the driving distraction guidelines are lifted, and you can provide experiences more in line with your existing adaptive UI.
[08:24](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=504s) Parked apps are activity-based, and are similar, or even the same, as the activities that are used on other devices, like phones or tablets, and we talk about parked apps in detail in the next section.
[08:37](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=517s) While parked app experiences reuse existing adaptive activities, there are still car-- car-specific quality guidelines that you need to meet, from manifest declarations and display cutouts to pausing playback when the car starts moving.
[08:52](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=532s) And to help automate that work, we've launched a new Android skill for parked apps.
[08:57](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=537s) So, before you get started, make sure that you've installed the Android CLI, and you can find that from this short link.
[09:03](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=543s) And then we have-- once you have that set up, run `android skills list` to explore the available skills.
```shell
android skills list
android skills add android-for-cars-parked-apps
```
[09:09](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=549s) There's a whole host of them, many different skills that you can actually use to put your Android development into the next gear.
[09:15](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=555s) And then specifically for Android for cars, you can use `android skills add android-for-cars-parked-apps` to the to add the skill to your agent's context.
[09:27](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=567s) Now, whatever your favorite AI agent may be, it gives you this step-by-step guidance to configure your manifest for Android Auto or for Android Automotive OS, handling car window insets and things like back navigation, enforcing driver distraction playback restrictions, and it can also even audit your video, game, or browser app before you submit them to Google Play.
### Car app categories overview
[09:51](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=591s) So, building for apps-- building apps for cars is also a bit unique because of the notion of these app categories.
[09:57](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=597s) As I mentioned earlier, there are certain categories of apps that can be used while driving, and then there are other categories of apps that can be used while parked.
[10:05](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=605s) These highlighted categories are those that can be used while driving.
[10:10](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=610s) Some of these are denoted with CAL, like I mentioned, this is the Car App Library, and apps in this category use templates like those that we saw a moment ago.
[10:19](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=619s) Now let me quickly go through these, I won't go into a lot of detail.
[10:22](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=622s) Starting with media apps, now these are apps that are playing audio, not video.
[10:26](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=626s) There are two ways of building them.
[10:28](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=628s) The one at the top here, denoted with MediaBrowserService, is a kind of the simplest option.
[10:34](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=634s) What you're doing is you're providing metadata whereas the infotainment screen interface fully takes care of rendering the playback and media browser UI in a car-optimized way.
[10:45](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=645s) The other option is to build media apps using the Car App Library, and this gives you more control and options to customize how you style and present your media apps, and Thomas will show us more about that in just a moment.
[10:57](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=657s) Navigation apps are, of course, a key use case, providing routes and turn-by-turn directions.
[11:02](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=662s) Rideshare driver apps also fall into this category.
[11:04](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=664s) Point-of-interest apps help you find access to useful nearby locations like EV chargers or parking spots.
[11:13](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=673s) Internet of Things or IoT apps let you access smart devices on the go, for example, home management.
[11:20](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=680s) And weather apps are also available, and can do things like deliver real-time radar, storm alerts, and location-specific forecasts.
[11:26](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=686s) And lastly, communication breaks down into three subcategories: extending basic notifications into the car, or messaging and video calling applications.
[11:40](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=700s) And then, there are the parked categories: video streaming apps, games, and web browsers.
[11:45](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=705s) And I'm happy to announce that since just a few weeks ago, publishing games on Android Auto and Android Automotive OS is available for all developers.
[11:55](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=715s) You'll notice that some of these categories say Open, others say In Beta, and others say Coming Soon.
[12:00](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=720s) Open means that any developer can submit an app in this category straight to production.
[12:05](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=725s) Beta means that while you can publish to internal or closed tracks, the app cannot be published into production unless you're accepted as part of an early access program.
[12:14](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=734s) The documentation for each of these categories includes more information and a link to our interest form.
[12:20](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=740s) And then Coming Soon is for categories that currently aren't supported, but we have plans to support them in the future.
[12:27](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=747s) Ultimately, our goal is to unify the platform.
[12:29](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=749s) We want you to be able to build and get the most reach by writing once and distributing to both Android Auto and Android Automotive OS, regardless of the category.
[12:41](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=761s) Now over to Thomas to talk about media.
### Car app library media updates
[12:43](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=763s) Cheers.
[12:43](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=763s) Great.
[12:49](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=769s) So, last year we introduced the Car App Library for media apps in version 1.8, bringing templated browsing UIs and custom actions to Android Auto.
[12:57](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=777s) This included the media playback template here seen on the left.
[13:01](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=781s) This year at I/O, we introduced more browsable UIs via Car App Library 1.9.
[13:07](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=787s) So, with CAL 1.9 reaching Beta, you can now unlock key feature updates across Auto and Automotive OS.
[13:14](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=794s) Highlights include brand customization via app expression, allowing you to tailor color and shape tokens with host-rendered layouts while maintaining safety rules, alongside new UI components like spotlight sections, condensed list items, scrollable chips, and a persistent mini-player.
[13:30](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=810s) Plus, CAL 1.9 expands media template support fully to AAOS, driving true platform unification across both ecosystems.
[13:40](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=820s) Our next iteration on the Car App Library is coming soon: CAL version 10.
[13:45](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=825s) CAL version 10 will bring more customized templates for communication apps, giving more robust and custom calling experiences while driving.
[13:53](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=833s) And we also include a new category of apps, and templates for apps, featuring conversational experiences while driving.
[13:59](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=839s) Lastly, even more functionalities in the works for more seamless park-to-drive transitions with the Car App Library templates.
[14:05](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=845s) Stay tuned for more coming soon.
### Park-to-drive capabilities
[14:07](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=847s) Park-to-drive capabilities using Car App Library allows your app to dynamically transition modes and display adaptive content while stationary, and seamlessly transition back to the Car App Library templates when driving.
[14:21](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=861s) Key applications include offering tailored authentication flows when you're stationary, or enabling a dedicated parked experience when you're, such as streaming video podcasts or music clips.
[14:32](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=872s) This integrates directly with the media playback template.
[14:36](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=876s) So, stationary vehicles grant drivers complete access to your app's native Android activity, enabling rich media like video streaming.
[14:44](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=884s) As soon as the car is put into gear distraction safeguards engage, so this prompts your app to shift back into the Car App Library media template to sustain compliant and uninterrupted audio listening.
[14:58](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=898s) We're at a transformative moment for in-car experiences.
[15:02](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=902s) Media apps want to evolve beyond traditional browse and play interfaces to deliver richer, more immersive, and interactive moments for drivers and passengers alike.
[15:11](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=911s) We're now going to dive into an example of how you can add a native video activity using the Media3 library to begin playing when the car transitions to park.
[15:20](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=920s) So to start this, you're going to connect a video rendering surface directly to your background playback instance.
```kotlin
override fun onStart() {
super.onStart()
...
controllerFuture = MediaController.Builder(
this,
sessionToken
).buildAsync()
controllerFuture?.addListener({
mediaController = controllerFuture?.get()
playerView.player = mediaController
}, ContextCompat.getMainExecutor(this))
}
```
[15:26](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=926s) You want to avoid instantiating a separate media player inside this activity, but instead, you want to maintain a central ExoPlayer or media player within your primary service, such as a Media3 media library service, handling combined with both audio and video streams.
[15:41](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=941s) So during motion, when no active service is bound, the player decodes audio only, but then when drivers open your video activity when parked, you want to attach its rendering surface directly to the underlying service player.
[15:53](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=953s) So using Media3, the `mediaController` implements player natively, so allowing a direct assignment, as you see here, `playerView` set-- `playerView.player` set directly to the `mediaController`.
[16:06](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=966s) So next, you'd want to register your native entry point utilizing `ParkedOnlyOnClickListener`.
```kotlin
val watchVideoAction = Action.Builder()
.setTitle("Watch Video")
.setIcon(videoCarIcon)
.setOnClickListener(
ParkedOnlyOnClickListener.create {
val intent = Intent(
carContext,
VideoPlayerActivity::class.java
)
.apply {
addFlags(
Intent.FLAG_ACTIVITY_NEW_TASK
)
}
carContext.startActivity(intent)
})
.build()
```
[16:12](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=972s) This wrapper provides an intent trigger within the header bar of your media playback interface.
[16:18](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=978s) So including an action to launch video playback, wrapping its selection listener in a `ParkedOnlyOnClickListener`.
[16:24](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=984s) So in driving mode, these taps are intercepted by the host app, which displays a system safety message, so you won't be able to go into that screen when you're driving, but when you're parked, the callback triggers the `startActivity` within `carContext` to launch the designated full-screen activity.
[16:42](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=1002s) Remember, in these Car App Library apps, you need to flag your video target as `distractionOptimized=false` inside the manifest so the operating system recognizes that this is only a parked workflow.
```xml
```
### Handling transitions from park to drive
[16:56](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=1016s) And lastly, let's see what happens when the driver shifts from park into drive.
[17:00](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=1020s) If the activity isn't distraction-optimized, if that remains active as the car moves, AAOS presents a system blocking overlay which tells you, basically, park to continue using the app.
[17:10](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=1030s) To avoid this blocked screen, our goal is to seamlessly return back to the media playback template without disrupting the audio.
[17:17](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=1037s) So when `isRequiresDistractionOptimization` evaluates to true here, we're basically going to clear the render the video rendering surface from your underlying media session and call finish on the player activity because it was launched on top of your CAL experience, finishing it returns directly to your media playback template and continues that audio playback.
```kotlin
class VideoPlayerActivity : ComponentActivity(){
override fun onStart() {
…
if (uxRestrictionsManager?
.currentCarUxRestrictions?
.isRequiresDistractionOptimization
== true) {
revertToCarAppTemplate()
}
}
private fun revertToCarAppTemplate() {
mediaControllerCompat
.sendCommand("CMD_CLEAR_VIDEO_SURFACE",
null, null)
finish()
}
}
```
[17:36](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=1056s) Maintaining that audio uninterrupted playback is key to a great user experience, so by keeping your media session active as a foreground service, sound continuously continues seamlessly across these state changes.
```xml
```
[17:49](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=1069s) You should also override the `onNewIntent` in the CAL screen to capture `SHOW_MEDIA_PLAYBACK` intents.
```kotlin
class MyCarAppSession : Session() {
override fun onCreateScreen(intent: Intent): Screen {
// 1. Link your active MediaSession token with Car App Library's MediaPlaybackManager
val mediaPlaybackManager = carContext.getCarService(MediaPlaybackManager::class.java)
mediaPlaybackManager.registerMediaPlaybackToken(mediaSessionToken)
// 2. Handle deep link if cold-started from the vehicle's media widget
handlePlaybackIntent(intent)
return HomeScreen(carContext)
}
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
// 3. Handle deep link when the session is already running
handlePlaybackIntent(intent)
}
}
```
[17:55](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=1075s) So that way, whenever users interact with a vehicle system media widget which is on the home screen of cars, the deep link routes them straight to your now playing view in Car App Library.
[18:05](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=1085s) So validating these transitions throughout the development process is really simple.
[18:09](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=1089s) You can execute adb commands on AAOS.
[18:11](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=1091s) For this case, it would be `emulate-driving-state drive` or `emulate-driving-state park` when you're ready to swap back between activities.
[18:20](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=1100s) So here's an example using our new sample Media3 media app using the Car App Library with park-to-drive video playback.
[18:27](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=1107s) So check this out at our adaptive Android booth downstairs and on our car-samples GitHub very soon.
[18:32](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=1112s) Park-to-drive capabilities are currently available on Android Automotive OS for media apps who've integrated with car CAL already for drive experience where they can offer more robust experiences while parked now.
[18:46](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=1126s) Check this out on our documentation very soon on developer.android.com and express interest there to feature this on your app.
[18:53](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=1133s) Paul.
### What's coming to the car app library
[18:58](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=1138s) Great.
[18:58](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=1138s) Thank you, Thomas.
[18:59](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=1139s) Before we wrap things up, I have a couple of ways to share with you to learn more about what's coming later this year.
[19:06](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=1146s) Like Thomas mentioned, CAL 1.9 is currently in alpha.
[19:09](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=1149s) It'll graduate into beta very soon.
[19:11](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=1151s) And then CAL 1.10 will be entering into alpha before the end of the year, so you can start evaluating conversational UIs and the latest communication and park-to-drive capabilities.
[19:24](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=1164s) Lastly, we're excited to share, like I mentioned, that games are available in Android Auto and Android Automotive OS, so this is really the perfect time to optimize your game titles for cars.
[19:35](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=1175s) To learn more about the implementation details, be sure to review the documentation in the "Build games for cars" guide.
[19:43](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=1183s) You can learn more about how to adapt your games for cars and keep track of what else is new and changing with Android for cars in our "What's new" page.
[19:52](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=1192s) We hope you've seen how cars and their users are ready for your apps.
[19:56](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=1196s) You can build your on your existing adaptive apps for rich parked experiences, and use a variety of the app Car App Library templates to create those safe driving-optimized experiences.
[20:09](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=1209s) Before you publish, you can test thoroughly using the Desktop Head Unit, the emulators, AAOS running on Pixel Tablet, or using the Firebase Test Lab.
[20:18](https://www.youtube.com/watch?v=8YkU3aPbQYA&t=1218s) You already have the skills to build for this ecosystem and millions of cars are waiting for your apps, so let's get that app on the road.