Android Auto Integration in Flutter

Ruchit Soni
2 min readApr 2, 2023

--

Before we begin, let’s understand about Android Auto.

Android Auto is a mobile app developed by Google that allows users to access certain features of their phone on their car’s infotainment system.
Some of the features that Android Auto provides include:

  • Maps and navigation
  • Music and media playback
  • Messaging and phone calls
  • Voice commands

To use Android Auto, you’ll need a compatible car stereo system that supports the feature, as well as a smartphone running Android 6.0 or higher.

In this blog, we will discuss music and media playback in Android Auto and how to accomplish it in the flutter App. We will use Audio Service package for this integration.

To make your app compatible with Android auto, we must include the following metadata in our AndroidManifest.xml file.

<meta-data
android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc" />

After adding this metadata, Your app will be listed in Android auto devices.

Note

You won’t be able to see your app in Android Auto unless you downloaded it from the Play Store. If you want to test your app for android auto, you can install DHU (Desktop Head Unit) in your IDE. This link contains simple instructions for installing DHU.

In app, we do not need to include any UI for Android Auto. Android auto have predefined templets. You just have to pass your data to it.

Let’s see how can we list app’s music to android auto.

As we are using Audio Service package for this, You need to add following methods.

final _mediaLibrary = MediaLibrary();
await _mediaLibrary.fillItems(); // Add your music files here
queue.add(_mediaLibrary.items[MediaLibrary.albumsRootId]!);

It will queue your music files. After that, you must pass MediaItem to broadcast the music file to Android Auto.

mediaItem.add(MediaItem(
id: value.id,
title: value.title,
duration: value.duration,
artUri: Uri.parse(artUri),
artist: value.artist));

You can also find a complete example of the above code in the Github repo.

You can now locate your music app in Android Auto and play music files in it.

Conclusion

In this article, we’ve explored how you can integrate Android Auto with a music player app built in Flutter.By using Flutter and the appropriate packages, you can build a high-quality music player app that works seamlessly with Android Auto.

--

--