1page.title=Getting Started with Auto 2page.tags="auto", "car", "automotive" 3page.article=true 4page.image=auto/images/assets/icons/auto_app_in_simulator.png 5 6@jd:body 7 8<div id="tb-wrapper"> 9<div id="tb"> 10 <h2>Dependencies and Prerequisites</h2> 11 <ul> 12 <li>Android 5.0 (API level 21) or higher</li> 13 </ul> 14 15 <h2>This class teaches you how to</h2> 16 <ol> 17 <li><a href="#dev-project">Set Up an Auto Project</a></li> 18 <li><a href="#build-it">Build Auto Apps</a></li> 19 <li><a href="#test-it">Run and Test Auto Apps</a></li> 20 </ol> 21 22 <h2>You should also read</h2> 23 <ul> 24 <li><a href="{@docRoot}design/auto/index.html">Designing for Auto</a></li> 25 <li><a href="{@docRoot}training/auto/audio/index.html">Providing Audio Playback with Auto</a></li> 26 <li><a href="{@docRoot}training/auto/messaging/index.html">Providing Messaging for Auto</a></li> 27 </ul> 28</div> 29</div> 30 31<p>Android Auto extends the Android platform into the car. When users connect 32their handheld devices running Android 5.0 or higher to a compatible vehicle, 33the Auto user interface provides a car-optimized Android experience on the 34vehicle's screen. Users interact with compatible apps and services through 35voice actions and the vehicle's input controls (like a touchscreen or dashboard 36buttons).</p> 37 38<p>Auto currently supports two types of apps:</p> 39 40<ul> 41<li><em>Audio apps</em> that allow users to browse and play music and spoken 42audio content in the car.</li> 43<li><em>Messaging apps</em> that receive incoming notifications, read messages 44 aloud via text-to-speech, and send replies via voice input in the car.</li> 45</ul> 46 47<p>You can enable your existing audio and messaging apps developed for 48phones and tablets to work in the car, without having to worry about 49vehicle-specific hardware differences. To enable your app for Auto, your 50app must target Android 5.0 (API level 21) or higher. Your app’s manifest must 51also declare the car capabilities that it uses, such as audio playback or 52messaging services. </p> 53 54<p>This lesson describes how to start building apps for Auto, including 55setting up your development environment and meeting the the minimum requirements 56to enable an app to communicate with Auto.</p> 57 58<p class="note"><strong>Important:</strong> If you are planning to develop 59apps for Auto, you are encouraged to begin enabling and testing your 60apps now. However, Auto-enabled apps cannot be published at this time. 61Join the 62<a href="http://g.co/AndroidAutoDev" class="external-link">Auto 63Developers Google+ community</a> for updates on when you will be able to submit 64your Auto-enabled apps.</p> 65 66<h2 id="dev-project">Set Up an Auto Project</h2> 67<p>This section describes how to create a new app or modify an existing app to 68communicate with Auto.</p> 69 70<h3 id="prerequisites">Prerequisites</h3> 71<p>Before you begin building apps for Auto, you must:</p> 72 73<ul> 74<li><strong><a href="{@docRoot}sdk/installing/create-project.html">Create or 75update your app project</a></strong> - Android 5.0 (API level 21) provides new 76APIs for implementing audio playback and messaging that is compatible with Auto. 77To access the new APIs, create a project or modify an existing project to target 78Android 5.0 (API level 21) or higher. This means you must set the manifest 79<a href="{@docRoot}topics/manifest/uses-sdk-element.html">{@code targetSdkVersion}</a> 80to 21 or higher. 81</li> 82<li><strong><a href="{@docRoot}tools/support-library/setup.html">Install the 83support library</a></strong> - If you are building messaging apps for Auto, you 84need the {@link android.support.v4.app.NotificationCompat.CarExtender} class 85contained in the 86<a href="{@docRoot}tools/support-library/features.html#v4">v4 support library</a>. 87This class allows you to create notifications that are compatible with Auto 88devices.</li> 89</ul> 90 91<h3 id="auto-metadata">Declare Auto capabilities</h3> 92<p>The Auto features that your app can access are controlled 93by the settings in your app manifest and a separate XML configuration file. 94Before adding Auto features to your app, you must first define the Auto 95XML configuration file and add a manifest entry referencing your XML file.</p> 96 97<h4 id="auto_xml">Define the Auto XML configuration file</h4> 98<p>Specify the car capabilities that your app uses in an XML file that you 99place in your project’s resources directory ({@code res/xml/}). For example, to 100extend an audio application for Auto, create a file called 101{@code automotive_app_desc.xml} and store it under your projects’s 102{@code res/xml/} folder. The {@code automotive_app_desc.xml} file contains the 103following metadata:</p> 104<pre> 105<automotiveApp> 106 <uses name="media" /> 107</automotiveApp> 108</pre> 109<p>The {@code <uses>} element declares the Auto capability your app 110intends to use. Multiple {@code <uses>} tags can be added if your 111application uses multiple car capabilities. The {@code name} attribute indicates 112the specific capability your app uses. The values supported are:</p> 113<ul> 114<li>{@code media} - The app uses the Android framework APIs to play music in 115a vehicle. Set this value if you are enabling an audio app for Auto.</li> 116<li>{@code notification} - The app displays message notifications in the car’s 117Overview screen, allows users select a message to be read aloud, and lets them 118respond through voice input. Set this value if you are enabling a messaging 119app for Auto. 120</ul> 121 122<h4 id="auto_xml">Add a manifest entry</h4> 123<p>In your app’s manifest ({@code AndroidManifest.xml}), provide a reference to 124the Auto XML configuration file you created in the previous section. Add a 125{@code "com.google.android.gms.car.application"} metadata entry under the 126<a href="{@docRoot}guide/topics/manifest/application-element.html">{@code <application>}</a> 127element that references your Auto XML configuration file. Omit the {@code .xml} 128file extension when specifying the configuration filename.</p> 129<p>The following code snippet shows how to include this reference in your 130manifest.</p> 131<pre> 132<application> 133 134 ... 135 <meta-data android:name="com.google.android.gms.car.application" 136 android:resource="@xml/automotive_app_desc"/> 137 138</application> 139</pre> 140 141<h2 id="build-it">Add Auto Features to Your Apps</h2> 142<p>After you have completed the steps described above, you're ready to add Auto 143features to your apps. See these additional topics to help you build apps for 144Auto:</p> 145 146<ul> 147<li><a href="{@docRoot}training/auto/audio/index.html">Providing Audio Playback for Auto</a> 148- Create apps that let users browse and play music in the car.</li> 149<li><a href="{@docRoot}training/auto/messaging/index.html">Providing Messaging for Auto</a> 150- Enable users to receive and reply to messages in the car.</li> 151</ul> 152 153<p class="caution"><strong>Important:</strong> Google takes driver distraction 154very seriously. There are specific design requirements your app must meet to 155qualify as an Auto app on Google Play. By adhering to these 156requirements, you can reduce the effort for building and testing your app. For 157more information, see 158<a href="{@docRoot}distribute/essentials/quality/auto.html">Auto App Quality</a>.</p> 159 160<h2 id="test-it">Run and Test Auto Apps</h2> 161 162<p>As you prepare to publish your app, make sure that your app looks correct 163when projected on the Auto user interface. Use the Android Media Browser 164simulator and Android Messaging simulators to view and test your audio or 165messaging apps in a screen that looks similar to what is projected on Auto.</p> 166 167<p>To get the simulators, open the 168<a href="{@docRoot}tools/help/sdk-manager.html">SDK Manager</a> and download 169them from <strong>Extras > Android Auto API Simulators</strong>.</p> 170 171<p>Before you begin testing, compile your app in your development environment. 172Install your app and the Android simulator for the features you want to test 173(that is, audio or messaging) on a physical or virtual device running Android 1745.0 (API level 21) or higher. To check the version of Android on the device, go 175to <strong>Settings > About > Android Version</strong>.</p> 176 177<h3 id="testing-audio-apps">Testing audio apps</h3> 178<p>To run and test audio apps:</p> 179 180<ol> 181<li>Install the Android Media Browser simulator 182({@code <sdk>/extras/google/simulators/media-browser-simulator.apk}) on 183the test device. You can do this using 184the <a href="{@docRoot}tools/help/adb.html#move">adb</a> command line tool.</li> 185<li>Enable <a href="{@docRoot}tools/device.html#device-developer-options"> 186developer options</a> on the test device.</li> 187<li>Install your app on the test device.</li> 188<li>Launch the Android Media Browser simulator to see how your audio app 189appears in Auto. If your app does not appear, stop the simulator from 190<strong>Settings > Apps</strong> then restart it.</li> 191</ol> 192 193<h3 id="testing-messaging-apps">Testing messaging apps</h3> 194<p>To run and test messaging apps:</p> 195 196<ol> 197<li>Install the Android Messaging simulator 198 ({@code <sdk>/extras/google/simulators/messaging-simulator.apk}) 199on the test device. You can do this using the 200<a href="{@docRoot}tools/help/adb.html#move">adb</a> command line tool.</li> 201<li>Enable the simulator to read notifications posted on the system: 202<ol type="a"> 203 <li>Enable <a href="{@docRoot}tools/device.html#device-developer-options"> 204developer options</a> on the test device.</li> 205 <li>Click <strong>Settings > Sounds & Notifications > Notification 206 Access</strong> and check the box labeled 207 <strong>Messaging Simulator</strong>.</li> 208</ol> 209<li>Install your app on the test device.</li> 210<li>Launch the Android Messaging Simulator to see how your messaging app appears 211in Auto. If your app does not appear, stop the simulator from 212<strong>Settings > Apps</strong> then restart it.</li> 213</ol> 214