Google 助理驾车模式下的媒体应用
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Google 助理可帮助驾驶员执行已在驾驶过程中完成的任务。
它通过提供一目了然的语音多模态体验来减少干扰。驾车模式有助于让每次驾驶都更安全、更明智、更顺畅、更愉悦。
正在使用驾车模式
当您开始在 Google 地图中开始使用导航时,设备会自动进入驾车模式。
停用驾车模式:
- 依次前往 Google 地图设置 > 导航设置 > Google 助理设置 > 管理驾车模式。
- 关闭驾车模式设置。
应用要满足的前提条件
为使驾车模式能与您的媒体应用搭配使用,应用必须满足以下要求:
驾车模式和播放控件
每个应用确定屏幕上显示的传输控件。为此,您可以将其 MediaSession
连接到 TransportControls
。例如,音乐播放器通常会显示以下控件:
任何其他受支持的操作均通过语音指令调用。
驾车模式会在两个位置显示推荐内容:“为您推荐”页面和应用浏览页面。这些屏幕看起来很相似:
为您推荐
应用浏览
Google 助理会调用 MediaBrowserService.onGetRoot()
并显示提示 EXTRA_SUGGESTED
来检索推荐内容。您应该返回一个包含可播放 MediaItem
对象的扁平列表。应用的浏览屏幕会显示列表中的所有项。如果列表中的项少于 15 个,“为您推荐”屏幕便不保证会显示推荐内容。
每个 MediaItem
都必须有媒体图片。如需提供 MediaItem
的类型,您可以将 CONTENT_TYPE
键值对添加到每个 MediaItem
的 MediaDescription 的 Bundle 中。这有助于提高相应内容在“为您推荐”页面中的排名。
CONTENT_TYPE
可能的值包括:
- 专辑
- 音乐人
- 播放列表
- 电视节目剧集
- 播客分集
- 音乐
- 有声读物
- RADIO_STATION
- 视频
- 新闻
测试
使用“媒体控制”测试应用验证您的应用。
已知问题
切勿在驾车模式下在前台打开媒体应用。例如,当 Google 助理调用 MediaBrowserService.onGetRoot()
来检索推荐内容时,您的应用应确保 PlaybackState
的状态为 STATE_NONE
。这可以防止将您的应用转到前台。目前无法让应用检测其是否处于驾车模式。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Media apps on Google Assistant driving mode\n\nGoogle Assistant helps drivers perform tasks they're already doing while driving.\nIt reduces distraction by providing glanceable, voice-forward multimodal\nexperiences. Driving mode helps make every drive safer, more informed,\nconnected, and enjoyable.\n\nUsing driving mode\n------------------\n\nA device automatically enters driving mode when you start navigating in Google Maps.\n\nTo disable driving mode:\n\n1. Navigate to **Google Maps Settings \\\u003e Navigation Settings \\\u003e Google Assistant settings \\\u003e Manage Driving Mode**.\n2. Turn off the **Driving Mode** setting.\n\nApp prerequisites\n-----------------\n\nIn order for driving mode to work correctly with your media app, the app must meet these requirements:\n\n- Follow all the directions in [Google Assistant and media apps](/media/implement/assistant)\n- Your app must declare that it supports media for Android Auto. Follow the directions at [declare media support for Android Auto](/training/cars/media/auto#manifest-car-app).\n- Handle [audio focus](/guide/topics/media-apps/audio-focus)\n- Use `PlaybackState` to [report errors](/guide/topics/media-apps/working-with-a-media-session#errors)\n- Implement a [MediaBrowserService](/guide/topics/media-apps/audio-app/building-a-mediabrowserservice) and a [MediaSession](/guide/topics/media-apps/working-with-a-media-session)\n- Your MediaSession must implement these callbacks:\n - `onPlay()`\n - `onPlayFromSearch()`\n - `onPlayFromUri()`\n - `onSkipToNext()`\n - `onSkipToPrevious()`\n - `onPause()`\n - `onStop()`\n- Keep the `MediaSession` metadata current by calling `setMetadata()`.\n\nDriving mode and playback controls\n----------------------------------\n\nEach app determines the transport controls that appear on the screen. Do this\nby [connecting its `MediaSession` to `TransportControls`](/guide/topics/media-apps/audio-app/building-a-mediabrowser-client#connect-ui-and-mediacontroller).\nFor example, a music player usually shows these controls: \n\nAny other supported actions are invoked via voice commands.\n\nMedia recommendations in driving mode\n-------------------------------------\n\nDriving mode displays recommendations in two places, the \"For you\" page and\nthe app's browse page. The screens look similar: \n**For you** \n**App browse** \n\nThe Assistant calls\n[`MediaBrowserService.onGetRoot()`](/guide/topics/media-apps/audio-app/building-a-mediabrowserservice)\nwith the hint\n[`EXTRA_SUGGESTED`](/reference/android/service/media/MediaBrowserService.BrowserRoot#EXTRA_SUGGESTED)\nto retrieve recommendations. You should return a flat list of playable\n[`MediaItem`](/reference/android/media/browse/MediaBrowser.MediaItem) objects. The\napp's browse screen displays all the items in the list. The \"for you\" screen\nis not guaranteed to show the recommendations at all if there are less than\n15 items in the list.\n\nEach `MediaItem` must have media art. You can provide\nthe type of a `MediaItem` by adding a `CONTENT_TYPE` key-value pair to the\n[Bundle](/reference/android/os/Bundle) in the\n[MediaDescription](/reference/android/media/MediaDescription) of each\n`MediaItem`. This helps improve the item's ranking in the \"for you\" page.\n\nThe possible values for `CONTENT_TYPE` are:\n\n- ALBUM\n- ARTIST\n- PLAYLIST\n- TV_SHOW_EPISODE\n- PODCAST_EPISODE\n- MUSIC\n- AUDIO_BOOK\n- RADIO_STATION\n- VIDEO\n- NEWS\n\nTesting\n-------\n\nUse the [Media Control test app](/guide/topics/media-apps/audio-app/media-controller-test)\nto verify your app.\n\nKnown issues\n------------\n\nIt is important to avoid opening a media app in the foreground\nwhile in driving mode. For example, when the Assistant calls\n`MediaBrowserService.onGetRoot()` to retrieve recommendations, your app should\nensure that the state of your `PlaybackState` is `STATE_NONE`. This prevents\nyour app from being brought to the foreground. Currently there is no way for an\napp to detect whether it is in driving mode or not."]]