Android Auto-Building Apps for Auto,Getting Started with Auto

desaco發表於2016-01-23

>Building Apps for Auto

 These systems provide a simplified interface for apps that can be used in a car, allowing users to take your app with them on the way to the grocery store or on a long road trip.

 Apps that work with Android Auto consoles run on a connected device, such as a phone or tablet. The app communicates via specific APIs with the in-dash console, which provides a user interface for the connected app that is designed for use in a car.

> Getting Started with Auto

> Android Auto extends the Android platform into the car. When users connect their handheld devices running Android 5.0 or higher to a compatible vehicle, the Auto user interface provides a car-optimized Android experience on the vehicle's screen. Users interact with compatible apps and services through voice actions and the vehicle's input controls (like a touchscreen or dashboard buttons).

> Auto currently supports two types of apps:

  • Audio apps that allow users to browse and play music and spoken audio content in the car.
  • Messaging apps that receive incoming notifications, read messages aloud via text-to-speech, and send replies via voice input in the car.
Before you begin building apps for Auto, you must:

heautomotive_app_desc.xml file contains the following metadata:

<automotiveApp>
   <uses name="media" />
</automotiveApp>

>The <uses> element declares the Auto capability your app intends to use. Multiple <uses> tags can be added if your application uses multiple car capabilities. The name attribute indicates the specific capability your app uses. The values supported are:

  • media - The app uses the Android framework APIs to play music in a vehicle. Set this value if you are enabling an audio app for Auto.
  • notification - The app displays message notifications in the car’s Overview screen, allows users select a message to be read aloud, and lets them respond through voice input. Set this value if you are enabling a messaging app for Auto.
 As you develop, you can run and test your app on your development machine using the Desktop Head Unit (DHU). The DHU replaces the existing simulators and enables your development machine to simulate a vehicle dashboard system running Android Auto.

> Run the DHU by connecting your mobile device to a development machine and setting up a connection to the head unit server over Android Debug Bridge (ADB). Follow these steps to set up tunneling and start the DHU:

  1. On the mobile device, enable Android Auto developer mode by starting the Android Auto companion app, and then tapping the Android Auto toolbar title 10 times. This step is only required the first time you run the companion app.
  2. If the server is not already running, select Start head unit server from the Android Auto menu.

    On the device, a foreground service appears in the notification area.

  3. In the Android Auto app, make sure the Only connect to known cars option is disabled.
  4. Connect the mobile device to the development machine via USB.
  5. Make sure the mobile device has its screen unlocked, otherwise it cannot launch the DHU.
  6. On the development machine, run the following adb command to forward socket connections from the development machine's port 5277 to the same port number on the Android device. This configuration allows the DHU to connect to the head unit server running on your phone over a TCP socket.
    $ adb forward tcp:5277 tcp:5277
  7. Start the DHU by running the command desktop-head-unit.exe (on Windows) or ./desktop-head-unit(on Mac or Linux) from the <sdk>/extras/google/auto/ directory.
    $ cd <sdk>/extras/google/auto
    $ ./desktop-head-unit

    By default, the head unit server connects over port 5277. To override the host or port (for example, to forward over SSH), use the desktop-head-unit --adb <[localhost:]port> flag, as in the following example:

    $ ./desktop-head-unit --adb 5999

相關文章