Android Auto Overview and Development Guide
Android Auto, Google’s car‑infotainment SDK launched in 2014, lets phones running Android 5.0+ connect via USB or Wi‑Fi to a head‑unit that displays voice, navigation, messaging, music and phone functions, while developers can only create music or messaging apps using a fixed UI, media service, and MediaSession interfaces.
Android Auto is Google’s car‑infotainment platform launched in June 2014. It is not a full operating system but an SDK that car manufacturers integrate into their own head‑unit OSes, or into Google’s Android system. More than 40 manufacturers have joined the Open Automotive Alliance to build an Android Auto ecosystem.
The platform currently offers core functions such as voice, navigation, instant messaging, music, and phone. Development interfaces are limited to music and messaging applications.
Android Auto Usage
To use Android Auto, a phone must run Android 5.0 or higher with Google APIs (stock Android). The phone connects to a compatible head‑unit via USB (or Wi‑Fi in newer versions) and Bluetooth (used only for calls). When the user selects a music app on the head‑unit, Android Auto lists the phone’s compatible music apps; selecting one starts playback.
Connection Principle
The head‑unit and phone communicate via USB (or Wi‑Fi) for graphics, touch events, and audio, while Bluetooth handles phone calls. All application logic runs on the phone; the head‑unit only displays UI and forwards input.
The phone’s Android 5.0+ system already includes the Android Auto SDK. Head‑unit platforms such as WinCE, QNX, or Linux must integrate the SDK. Calls are still handled via standard Bluetooth HFP.
Android Auto Application Development
Only music and messaging apps can be built for Android Auto. The following steps illustrate how to develop a music‑type app.
1. Create a New Android Auto Project
In Android Studio, create a new project and select the Android Auto platform. Choose the music template to generate a project that supports Android Auto music functionality.
2. Add Android Auto Support to an Existing App
Use File → New → Android Auto → Media Service . The project’s minimum SDK must be 21 or higher; otherwise the Media Service option is disabled.
3. Configure Android Auto Support
Both methods generate an automotive_app_desc.xml file in the res/xml folder:
<?xml version="1.0" encoding="utf-8"?>
<automotiveApp>
<uses name="media"/>
</automotiveApp>Add the following metadata to AndroidManifest.xml to declare Android Auto support:
<application>
...
<meta-data android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc"/>
</application>4. UI Customization
The UI is largely fixed; developers can only change two colors (primary dark and accent) via res/values/styles.xml .
5. Detect Car Connection via Broadcast
IntentFilter filter = new IntentFilter("com.google.android.gms.car.media.STATUS");
BroadcastReceiver receiver = new BroadcastReceiver() {
...
public void onReceive(Context context, Intent intent) {
String status = intent.getStringExtra("media_connection_status");
boolean isConnectedToCar = "media_connected".equals(status);
// adjust settings based on the connection status
}
};6. Determine Car UI Mode
public static boolean isCarUiMode(Context c) {
UiModeManager uiModeManager = (UiModeManager) c.getSystemService(Context.UI_MODE_SERVICE);
if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_CAR) {
Log.d(TAG, "Running in Car mode");
return true;
} else {
Log.d(TAG, "Running on a non-Car mode");
return false;
}
}7. Implement MediaBrowserService
Declare the service in the manifest (exported must be true):
<application>
...
<service android:name=".QQMusicAndroidAutoService"
android:exported="true">
<intent-filter>
<action android:name="android.media.browse.MediaBrowserService"/>
</intent-filter>
</service>
...
</application>The service must implement two key methods:
public BrowserRoot onGetRoot(String clientPackageName, int clientUid, Bundle rootHints);
public void onLoadChildren(final String parentMediaId, final Result<List<MediaItem>> result);Example implementations:
return new BrowserRoot("root", null);These methods provide the root directory and child media items to the head‑unit.
8. Playback Control with MediaSession
Create a MediaSession to handle playback commands (replaces the old RemoteControlClient ).
MediaSession mSession = new MediaSession(this, "QQMusicAndroidAuto");
mSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS |
MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
mSession.setCallback(new MediaSessionCallback());Define the callback to respond to user actions:
private final class MediaSessionCallback extends MediaSession.Callback {
@Override public void onPlay() {};
@Override public void onPause() {};
@Override public void onSeekTo(long position) {};
@Override public void onPlayFromMediaId(String mediaId, Bundle extras) {};
@Override public void onSkipToNext() {};
@Override public void onSkipToPrevious() {};
@Override public void onCustomAction(String action, Bundle extras) {};
@Override public void onPlayFromSearch(final String query, final Bundle extras) {};
}Finally, link the session token to the service:
setSessionToken(mSession.getSessionToken());Conclusion
Developing for Android Auto is relatively straightforward: implement a few required interfaces, provide media data, and the system handles UI rendering. The main limitation is the inability to fully customize the UI, resulting in a uniform appearance across apps.
Reference:
Google Android Auto developer site: https://developer.android.com/training/auto/index.html
Tencent Music Tech Team
Public account of Tencent Music's development team, focusing on technology sharing and communication.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.