0

I am trying to build a media application for Android Automotive (not to be confused with Android Auto!). It is an application which can be installed directly on car hardware.

Anyways: When I launch the application in the Polestar 2 emulator (or in the car itself), it hangs on the initial screen with a "Loading content..." message.

I have implemented a class extending MediaBrowserServiceCompat, where I am overriding onGetRoot(...) and onLoadChildren(...):

@Nullable
@Override
public BrowserRoot onGetRoot(@NonNull String clientPackageName, int clientUid, @Nullable Bundle rootHints) {
    Log.i(TAG, "onGetRoot()");
    return new MediaBrowserServiceCompat.BrowserRoot(MusicLibrary.getRoot(), null);
}

@Override
public void onLoadChildren(@NonNull String parentId, @NonNull Result<List<MediaBrowserCompat.MediaItem>> result) {
    Log.i(TAG, "onLoadChildren()");
    result.sendResult(MusicLibrary.getMediaItems());
}

("MusicLibrary" is just this file, which I am using temporarily to try to get things working: https://github.com/googlecodelabs/android-music-player/blob/master/base/mobile/src/main/java/com/example/android/musicplayercodelab/MusicLibrary.java)

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
    android:allowBackup="true"
    android:appCategory="audio"
    android:dataExtractionRules="@xml/data_extraction_rules"
    android:fullBackupContent="@xml/backup_rules"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.Test"
    tools:targetApi="31">

    <service
        android:name=".MediaBrowserService"
        android:enabled="true"
        android:exported="true">
        <intent-filter>
            <action android:name="android.media.browse.MediaBrowserService"/>
        </intent-filter>
    </service>
    
    <receiver android:name="androidx.media.session.MediaButtonReceiver" android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MEDIA_BUTTON" />
        </intent-filter>
    </receiver>

</application>


<uses-feature android:name="android.hardware.type.automotive" android:required="true" />
<uses-feature android:name="android.hardware.wifi" android:required="false" />
<uses-feature android:name="android.hardware.screen.portrait" android:required="false" />
<uses-feature android:name="android.hardware.screen.landscape" android:required="false" />

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

compileSdk and targetSdk is 33. minSdk is 29.

Dependencies (perhaps some can be removed):

implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.car.app:app:1.2.0'
implementation 'androidx.media:media:1.6.0'

Looking at Logcat, I just get "onCreate()", "onGetRoot()", and "onLoadChildren()". However, nothing is displayed on the screen, except for the "Loading content..." message in the middle of the screen.

Does anybody have a clue about what I am missing here?

Morten
  • 684
  • 1
  • 5
  • 15
  • Additional information: I am also signed into Google Play store on the Polestar 2 emulator (and the physical device (car)), which pulled an update of the "Google Automotive App Host" to the version from May 3, 2023. However, the problem persists. – Morten Aug 01 '23 at 18:03

1 Answers1

0

The MusicLibrary.java you linked creates a list of MediaItems with FLAG_PLAYABLE (see https://github.com/googlecodelabs/android-music-player/blob/master/base/mobile/src/main/java/com/example/android/musicplayercodelab/MusicLibrary.java#L73C44-L73C57.

I think AAOS will not allow that, the root of your MediaItem tree must consist of FLAG_BROWSABLE items that make up the 4 category icons at the top of the MediaBrowser. Check also https://developer.android.com/training/cars/media#root-menu-structure.

Further down the tree hierarchy you can put your playable items.