Android Automotive中MediaBrowserServiceCompat卡在「加载内容...」问题排查
Android Automotive车载媒体应用卡在「加载内容...」界面问题
问题背景
开发一款直接安装在车机硬件上的Android Automotive车载媒体应用(非Android Auto),在Polestar 2模拟器及实车中启动后,界面始终停留在初始屏幕,显示「加载内容...」提示。Logcat显示onCreate()、onGetRoot()、onLoadChildren()均已执行,但界面无后续内容加载。
已实现内容
MediaBrowserServiceCompat子类核心代码
@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为标准媒体库实现,包含媒体项的构造与数据返回逻辑
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"/> </manifest>
项目基础配置
- compileSdk、targetSdk版本:33
- minSdk版本:29
- 核心依赖:
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'
疑问
已完成上述实现与配置,但界面始终停留在「加载内容...」状态,请问遗漏了哪些关键配置或代码实现?
内容的提问来源于stack exchange,提问作者Morten
相关产品推荐
相关产品推荐

