How to Build Android Apps for Cars (Google I/O’19)

How to Build Android Apps for Cars (Google I/O’19)

vision for Android Auto is to bring a safe and seamless
experience to every car, which means we provide
a way for people to connect their digital
lives seamlessly into the car. So the same apps
and services you use on your phones
and other devices are available just as
easily in your car. If you attended our session
yesterday or have been paying attention to what we’ve been
up to, you’ll know that we have two in-car platforms– Android Auto and
Android Automotive OS. The first of these
platforms, Android Auto, runs on the phone and
integrates with compatible cars. This means your
apps and services will be available on the screen
in a driving-optimized way. You can interact with these
apps through your car’s screen and controls, but everything
is running from the phone. We initially previewed
Android Auto at I/O in 2014 and launched to
consumers in early 2015. We are proud to say
that Android Auto is now available in 36 markets in
more than 500 different car models from 50-plus brands. And we have thousands of
apps already compatible with Android Auto, and continue
to see growth in this area. Our partnership
with developers is a key reason for the
success of Android Auto. And we hope to bring those apps
to our newest platform, Android Automotive OS. So the second platform,
Android Automotive OS, is what we are going
to talk about today. With Automotive OS,
Android is running as the embedded infotainment
platform in the car, enabling a much deeper,
more seamless experience from everything from
navigating with Google Maps, to listening to music
with Spotify, to adjusting your climate temperature. And unlike Android Auto,
the apps and services are running directly
in your car. And it doesn’t matter what
kind of phone you have. We previewed Automotive OS
the last couple years at I/O and announced a few weeks ago
that the first consumer vehicle to launch with the
embedded platform will be available in the
Polestar 2 launching in 2020. And you can check that
out in our sandbox, if you haven’t already. So we hear from user surveys
that there are four key things people like to do in the cars– navigate between locations,
communicate with phone calls or messages, listen
to music via Spotify, and control various
aspects of the car, such as adjusting
their seat position. With a platform like
Android in the car, we intend to enable app
developers to develop apps in many of these categories. In fact, we anticipate
that you’ll develop apps beyond these
categories, and we want to enable you to do that
thoughtfully and over time. So today, we’re going
to take you on a journey through the app development
process, starting with design. So we know that the automotive
space is very complex. There are a myriad of screen
sizes, shapes, resolutions, different input modalities,
and countless regulations. And we know that we want
to prioritize the driver. Their primary responsibility
is to focus on the road. Everything else is secondary. So the first vertical which
we want to enable is media. And we have borrowed
a lot of learnings from Android Auto over
the past few years where the user
experience is developed by Google in collaboration
with app developers. And it will be
customizable by car makers. So media will enable developers
to have a consistent experience across Android Auto and
Android Automotive OS so that the two
platforms are similar. It will enable developers to
maintain their apps branding, not worry about
driver distraction or making sure that it works
across the myriad of screen sizes. And for car makers,
it will allow them to customize the media
experience based on the system design and branding. So now I’m going to walk
through four key themes that we think about when
designing for automotive. These are the principles
that we used in order to design for media. The best part is,
as developers, you don’t have to worry
about any of these. And I’ll go through
these in detail. So the first theme is our
driver distraction guidelines. We take the complexity out
of designing for automotive. Here’s a sample of
what we consider. Information should be
timely and relevant. Targets should be easy to touch. And we shouldn’t distract the
driver with complex animation or video. And we want to
encourage people to keep their hands on the wheel. So the second theme is
our adaptive framework. And as I mentioned
earlier, the car landscape isn’t getting any simpler. So we’re working with
car makers globally to roll out a framework
across their cars in a way that keeps it
consistent for developers. Third is a
voice-optimized UI, which supports hands-free
driving with features like voice-optimized
search with speech-to-text, and the Google Assistant,
which will provide users quick access to
apps and content, without having to interact
directly with their screens. And finally, we want to make
sure the content is recognized by your users through the use
of your app’s branding, icon, and colors. So that’s all the stuff
that we’ve done for you. Now, I’m going to talk about
how to design media apps. So first, define
your architecture and determine the
primary navigation items. Design an icon and
label for each. Next, choose how you want
your content to be displayed. Should it appear in
a grid, or a list? This will likely be determined
by the type of content that you have. For example, you may want
to use a grid for content across categories, and
you may want to use a list to depict songs in an album. Third, customize your
playback controls, such as forward and
back 30 seconds, a thumbs-up or thumbs-down
to signify like or dislike. And make sure you design your
icons to represent each state. So fourth, design a
screen, if needed. And we recommend
using a dark theme. You may choose to implement
via Bluetooth, a PIN, username, or password, or
any combination of these. Next, design your settings. And again, we recommend
using a dark theme for this. Settings should include things
like accounts and profile information, app preferences
related to driving, and sign-in and
sign-out functions. And finally, provide
your branding elements– an app icon, which will be
used on all screens that depict content, an accent color
which a car maker may choose to implement, navigation
icons and labels, and any custom controls
that you wish to include. So to recap, we take care
of driver distraction so that you don’t need
to worry about it. We have an adaptive
framework that makes it so that your content
is displayed correctly across screens. We optimize for voice
to make driving safe. And we make sure that your brand
is recognized by your users, and designing for
Automotive is easy. So to get more details
and more information, go to our UX guidelines
in the link on the screen. So thank you, very much. Now that I’ve talked to you
about designing for media apps, I’m going to hand
it over to Igor, who’s going to talk about
developing for media apps. [APPLAUSE] IGOR RAZUMEIKO:
Thank you, Heather. Hello, everyone. My name is Igor Razumeiko. I’m a tech-lead working
on enabling applications to run on Android Automotive OS. So as Heather mentioned,
Android Automotive OS is where your applications
run natively inside of a car. And a phone is not needed. Also, she mentioned
that we are taking care of some driver
distractions, so you don’t have to. So my part of the
talk is going to be about what you, as
a developer, need to do to enable your
application in the car. And we are starting
with media apps. So first of all,
Android Automotive OS is a different platform, but it
is very similar to Android Auto when it comes to
integrations of media apps. In fact, we kept almost all
integration points from Android Auto to Android Automotive OS. So let me go through
the steps that you need to do to enable your
application for a car. Well, first of all, you need
to build your audio service. And this part of
the talk, I’m not going to explain to
you how to do it, because it’s totally on you. If your application uses
Google Play services, that’s great, because
you still can use them, because we kept them
in the car as well. We removed some models that
didn’t make sense in the car. But if we removed something
that you deeply care about, please talk to us and we’ll
consider bringing them back. Some of Google Play
service’s models, we already adapted for a car. Like things with
heavy UI, you’ll be already riding in the car. And you’ll have UI that is
themed for a specific car. So now, step two is familiar
for those of you who already did adaptation for Android Auto. You need to integrate
with MediaSession and implement
MediaBrowserService. And MediaSession
is basically how you control your
music playback– previous, next, pause, play. And this is how it will be
integrated with car hardware. MediaBrowserService is needed if
you want to expose the content, but you want to provide
to user to play. So this is how you build
your tree structure, which user can navigate to find the
right music to play or right podcast to play. So if you integrated
with Android Auto, you already have done it. So all these steps,
we already covered in our previous sessions. There is plenty
of documentations online on our developer
site how to do it. Some specifics when you
integrate in MediaSession specifically for a car. Well first of all, when
your service is created, you need to create a
MediaSession immediately. So it will be ready to
play when the car starts. And to prepare a music to
play faster when the user hits a key, so you react
to onPrepare(), and you set your
MediaSession to STATE_PAUSED. You don’t need to start
playback automatically. Your car will tell you
when it’s ready to play, because it keeps
the state of what was happening in music
if user paused it before leaving the car
or if user was playing when they left their car. And also framework will
remember which application was playing the media last time. So it will resume
exactly same application when driver gets
back into the car. So to recap– these
two steps, building a service and implementation
of MediaSession and MediaBrowserService,
is exactly the same steps that you would have done for
integrating with Android Auto. So it should be known to you. So now let’s talk about
things that are new, that are specific for
Android Automotive OS. First of all, you need to
declare your application that is done for cars. And this is pretty simple. You just add these two lines to
your manifest, and you’re done. This way also you have a
Play Store in your car. It will recognize that your
application was done for a car, and it will be available
for users to install. Next step is, it could be
easy or it could be hard. If your application
is [INAUDIBLE] already with your playback services
separate from your user interface, you just need to
exclude your mobile activities from a packet that you’re
going to be making for a car, because mobile activities
are not designed for a car. They are not
distraction-optimized, so they will not be
allowed in your car, except with a couple
of exceptions that I’m going to talk about later. One exception is
activity, because you don’t
have your phone to start playing in the car. You need your user
to sign in somehow. And so you implement activity
which is designed for a car. And since you don’t have
any other activities, you don’t launch it yourself. The framework will
launch it for you. And the way you do it–
you will set an error state on MediaSession, and
you set specific extra with the resolution intent to
take you to a sign-in activity. So you set extra, and
you set playback session into an error state, saying
authentication required. Settings activity is optional. If you need to control
playback, for example– maybe you need to
download music, and you need to set
a playback quality– settings activity is optional. The way you declared it,
it’s pretty standard. You just say, intent filter
applications preferences, and this will be
automatically recognized by the platform itself. And it will display an icon,
so user can go to settings. Sign-in and settings activity
are driver distraction not optimized. So will only be allowed
when the car is parked. All right. Some things to consider. When you’re implementing
your activities, don’t set them to any
specific orientation. You can’t rotate your car. Avoid using notifications. Notifications are not
optimized for driving, and the user might miss one. So only important
notifications will be displayed when the user is
driving, and everything else– just be mindful when
using notifications. Those are even harder
to see in a car because drivers are
focusing on the road mostly. So don’t use those. In the future, we might
even disable them. Permissions, also like not
really a great idea to ask, as a user is driving,
to ask for permissions. If you absolutely have
to ask for permission, do it in your settings
and sign-in activity. And car screens
could be very large. So if you provide graphics
to an infotainment system, provide all the vector
images where possible. Because some screens
are very large, and your bitmaps might
not look very great. So let’s recap. So you build your audio
service, which you probably already know how to do it. You implement MediaSession and
MediaBrowserService interfaces. And you implement
all the steps that I was talking about that
are specific for a car. So now, Roberto is going
to talk to you about tools that we built in for working
with applications for cars. And he will also go for
some practical demo, how to build a music
application for a car. [APPLAUSE] ROBERTO PEREZ: Thank you, Igor. My name is Roberto
Perez, and I’m going to walk you
through the changes we have done to the
Android Elementals to support Automotive OS. Some of the changes we’ve
done are on Android Studio. What we have included
are new code templates that are going to allow you
to develop for Automotive OS more easily. The first template
I want to talk is the new project template. This is going to
create a project that contains support for both
Android Auto an Automotive OS. And it also includes a
skeleton of a media service. You will have to do the work
of implementing your business logic and your
streaming, but it’s going to give you a
framework where to start. The second template is a new
module Automotive template. This is in the case that you
already have an application, and this application
already implements all the necessary
pieces for Android Auto, and you want to extend it
to support Automotive OS. The template is going to add
a new module, the declarations to indicate that
this application is meant to be run on the car. And you can then connect it to
your existing business logic. Now, when it gets to the
point of testing your code, we don’t expect you to go and
buy cars to be able to test it. The best option is to
use an Android emulator. And to that end,
we are including two new virtual devices
that you can use. The first one is a generic
Automotive OS virtual device. This contains a reference
implementation of the media experience, and
Google’s Play services, and all the necessary
pieces for you to be able to test
your application. You can also see the same
system image in the Codelabs here in I/O where
you can play with it. The second virtual device is
actually provided by Volvo. It’s the same experience
that you’re going to see in the Polestar 2 car. You actually can see this
in action in our garage, and it contains the
Polestar version of the media experience. Instructions on how to
download it and install it are in the link on the screen. And of course, as we introduce
new features, more form factors come into play,
different screen sizes, we are going to be updating
the list of emulators. The tools I just described
are available today as part of the Android
Studio 3.5 beta. Just a note– the
Automotive features are behind the feature flag. Instructions on
how to enable them are on the link on the screen. So now it’s time
to do some demo. And from the framework
that Igor presented, the three steps on how
to build a media app, I am going to focus
on the third one– the Automotive-specific
features. So to fast-forward
my demo, I’m going to start from an
existing project. This project is a simplified
version of the universal media sample app. This sample application
is provided by Google. It’s publicly
available on GitHub. It contains all the pieces of
a complete media application. It does the streaming,
implements MediaSession and MediaBrowserService. So I’m going to start
from here, and I’m going to use the Android
Studio template to add Automotive support. I’m going to test
it on the emulator. And in the end, we’re going
to have a fully-fleshed media application running
on Automotive OS. So now, if we can
switch to my laptop. So this is my project. It contains two modules. One of them is mobile. This module contains all
the assets for the phone. So it contains sign-in
activities, all the activities that you see on the phone. And it’s the one that generates
the .apk that powers Android Auto. The second module
is called media. It contains a music service,
which does all the business logic for playback and
implementation of MediaSession and MediaBrowserService. So as you can see, I’m
starting from a good place. It contains all the pieces
for supporting Android Auto. So what I’m going to do
is I’m going to extend it to support Automotive OS. I’m going to use the
new module template. I’m going to select
Automotive, and I’m going to complete the form. The first thing, I need to
give my application a name. This is the name that
is going to appear to the users on
the app selector. I’m going to say, Aural. This is the fake
application name we’ve been using for the demos. I’m going to rename
my module Automotive, to make it clear
that this is where all the Automotive-specific
things are going to go, like all the vehicle-optimized
activities and assets. And I need to change
my package name to match the code
I already have. The wizard is going
to ask me if I want to create a new media service. And the truth is, we already
have one in the share module, so I’m going to say, no. And now we just need to wait
for Gradle to do its thing, and we get our third module. If we look a little
deeper, we can see that this manifest includes
the declarations to say that this is an
Automotive OS application. But my module is empty. There’s no code here,
and that’s because we said we are going to use the
content of the media module that we already have. So for that, I need
to add a dependency. I’m going to add a line
to this Gradle file. And this is going to tell
the Automotive module to reuse the media service that
we have on the media module. My media module uses
Java 8, so I also need to copy this
deceleration over there. And that’s it. This is all the code I need
to have an Automotive OS application. Now, in order to test it, I
said before, the best option is to use an emulator. And this is where we added some
new features to Android Studio. We have a new
section, Automotive. And here’s where we have
the two new virtual devices. So I’m going to
complete this wizard, and we have a new virtual
device ready to launch. So here, we have the
emulator running. While this is booting, I’m
going to complete my code. All I need to do
is to compile it. Now, you’re going to notice
there is this red cross here. And that’s because
Android Studio is complaining that there’s
no activity to launch. And that’s actually by
design because, in our case, this application doesn’t
have a launcher activity. The application is going
to be launched by the media experience by the system. So I’m going to
select nothing here. So this is going to tell
Android Studio to just compile and install it,
but not to launch it. And I want to show you
the media experience. These are the applications
we have by default. And if I compile– we just need to wait
a couple of seconds. Android Studio just told me
that it’s compiled successfully and installed successfully. So now, we have our
new application here. If I click on it, we have
an application working. I can select a song. This is going to start playing,
and we have our application working on Automotive OS. I want to show this
same application, how it looks on the Polestar. So I’m going to
select the Polestar 2, and I’m going to launch
that virtual device. While this is booting, we
can start compiling again. Oh, I need to wait. OK. Application is ready. And we can see this
same application, how it looks a little
different, because this is using the
customizations that Volvo has done on their own system. OK, and that’s the demo. Can we switch back
to the presentation? OK, that went well. Thank you. [APPLAUSE] Now with our code ready,
we are ready to publish our application. And for that, what
we’re going to be using is using app bundles. App bundles is a
format that allows you to package all your
assets, both for the phone and for the car, in a
single package that you can upload to Google Play Store. Then, Google Play Store
is going to take care to distribute the corresponding
package to each device. This is going to streamline the
way you manage your uploads. Google Play Store is going to
start receiving submissions later this year. So to summarize, I want
to give you a roadmap, depending on where you are
on your development process. Let’s say that you are
starting from scratch. You don’t have an
application yet. Then, there are two
options where to start. One is you can use the
templates that I showed you on Android Studio. This is going to give
you the skeleton, the necessary structure
to start from, but you will have to
implement all their business logic yourself. The other option is to start
from the other end, that is using this universal
media player sample app. This contains all the code. It implements support for all
the form factors in Android, including Automotive OS. And it has all the
implementation and solutions for common problems
while dealing with media. Then, maybe you already
have an application, but it doesn’t implement
Media Service yet. So you can use the Automotive
Media Service template. This is going to give you the
skeleton of a Media Service. It’s going to add
it to your project. You will need to hook that up
to your existing business logic. Or maybe you already have
an Android Auto application, but it’s built as a
monolithic codebase. So in that case, you will need
to work on modularizing it. And by that, I mean
separating your phone assets from the Media Service. That way, you are going to be
able to reuse use your Media Service for Automotive. If you got to this point,
you are almost done. All you need to do is
to add the declaration to support Automotive OS. And if your application
needs sign-in or settings, you need to develop
vehicle-optimized activities and configure it, as
Igor explained before. In the end, we expect a
project similar to this– one module dedicated
to the phone that is going to power both the phone
experience and the Android Auto experience, and a module
for Automotive that is going to contain
vehicle-optimized assets meant to be run on the car. And then a third
module containing most of your business logic– the implementation
of MediaSession and MediaBrowserService– as a
shared module between the two. We have updated the
Android developers website with step-by-step instructions
on how to get this done. And if you want to
get your hands dirty, we have the Codelabs here at
I/O with these little bench units where you
can test creating an application from scratch. Later today, we’re going
to be hosting Office Hours, and we would love
to hear from you. If you have any questions
on what we presented today, or if you have any other
ideas on the Automotive space, we would love to hear you. In the same area,
we have two cars. One of them is the Polestar 2
running the system experience that I presented before. So come and see
Automotive OS in action. So this is it. Here are all the links
that we presented during today’s session. We are hoping to see your
applications hitting the road. Thank you, for coming. [APPLAUSE] [MUSIC PLAYING]

About the Author: Michael Flood


  1. boeeee still no navigation apps for android auto. please open up one of the main core usages of android auto for developers which is navigation.

  2. Nice video, very happy to see advances in this platform! I've run through to try to download and run the Polestar 2 system image from Android Studio 3.5, but unfortunately after adding the new source the only way to get something similar to what's displayed in the demo time is creating a new hardware profile. The problem is that the result is quite different than the one presented, so wondering if there is a place where I can find more documentation about how to set up automotive emulators.

  3. Since the Waze purchase… is there no way to integrate custom maps within your app to be displayed in the car?

Leave a Reply

Your email address will not be published. Required fields are marked *