0

So, I followed the official guide here https://developer.android.com/training/auto/start/index.html to create a very basic Android Auto Audio App. For the moment it does nothing, other then declaring what needs to be declared in the manifest and implementing empty onGetRoot() and onLoadChildren().

Problem is, that it is not being recognized by the Android Auto app.

Any idea where to get a working example? What could be wrong?

Manifest:

<service
    android:name=".MyService"
    android:enabled="true"
    android:exported="true">
    <intent-filter>
        <action android:name=
            "android.media.browse.MediaBrowserService"/>
    </intent-filter>
</service>

automotive_app_desc.xml:

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

service:

public class MyService extends MediaBrowserServiceCompat {
public static final String MEDIA_ID_ROOT = "__ROOT__";

@Override
public BrowserRoot onGetRoot(String clientPackageName, int clientUid,
                             Bundle rootHints) {

    //TODO: check if the client is allow access

    return new BrowserRoot(MEDIA_ID_ROOT, null);
}

@Override
public void onLoadChildren(final String parentMediaId,
                           final Result<List<MediaBrowserCompat.MediaItem>> result) {

    // Assume for example that the music catalog is already loaded/cached.

        List<MediaBrowserCompat.MediaItem> mediaItems = new ArrayList<>();

    // Check if this is the root menu:
    if (MEDIA_ID_ROOT.equals(parentMediaId)) {

        // build the MediaItem objects for the top level,
        // and put them in the mediaItems list
    } else {

        // examine the passed parentMediaId to see which submenu we're at,
        // and put the children of that menu in the mediaItems list
    }
    result.sendResult(mediaItems);
}
Abdul Kawee
  • 2,687
  • 1
  • 14
  • 26
Demiurg
  • 1,597
  • 8
  • 26
  • 40

2 Answers2

3

You have to go to Android Auto settings, tap many times on the Version entry (the last one) to unlock Developer settings. Then tap on Developer settings menu item and enable Unknown sources. Restart Android Auto and if your app it's ok it will be listed. Worked for me

ico2k2
  • 61
  • 5
1

I didn't see this included in your snippet from the manifest, but double check that this line is also there.

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

I created a sample app matching everything you have (plus the line above), and it appears in Android Auto on the mobile device, as well as the Desktop Head Unit.

salminnella
  • 744
  • 2
  • 6
  • 17
  • That is weird, I literally copied what you have into a sample app and it recognized just fine in Android Auto on the mobile device. After launching AA, selecting the headphones icon for media apps will open the last used media app (most likely Google Play Music). If it recognizes other media apps (through automotive_app_desc.xml), there will be a little arrow next to the icon signifying that. Tapping the headphones icon again, will bring up the list of available apps where you should see yours. Have you installed the desktop head unit? Try running that and see if the app is recognized there. – salminnella Feb 27 '18 at 18:42
  • 3
    If you are running Android Auto on the phone (without the desktop head unit), you will want to turn on "Unknown sources" in the developer settings. – Vinay Dandekar Mar 10 '18 at 02:29