支持语音操作
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
将语音操作集成到媒体应用中,以最大限度地减少干扰,从而提高驾驶员的安全性和便利性。当 Android Auto 或 Android Automotive OS (AAOS) 检测到并解读语音操作时,它们会通过 onPlayFromSearch
回调将该操作传递给您的应用。
收到回调后,应用会找到与查询字符串匹配的内容,然后开始播放。您的应用必须考虑各种查询类别,例如流派、音乐人、专辑、歌曲名称、电台或播放列表。此外,您的应用还必须处理空查询字符串,这表示用户发出了常规的音乐请求。
如果您的应用已在播放某一媒体项,则用户可以通过说“播放《[歌曲名]》”让应用播放另一首歌,而无需用户查看或轻触汽车的显示屏。用户可以通过点击方向盘上的相应按钮或说出启动指令“OK Google”来发起查询。
当 Android Auto 或 AAOS 检测到并解读语音操作时,Android Auto 或 AAOS 会通过 onPlayFromSearch
将该语音操作传递给应用。收到此回调后,应用会找到与 query
字符串匹配的内容,然后开始播放。
用户可以在查询中指定不同类别的字词:流派、音乐人、专辑、歌曲名称、电台或播放列表等。构建搜索支持功能时,请考虑您的应用适用的所有类别。如果 Android Auto 或 AAOS 检测到指定查询符合特定类别,则会在 extras
参数中附加 extra。您可以发送以下额外内容:
考虑使用一个空的 query
字符串,以供 Android Auto 或 AAOS 在用户未指定搜索字词的情况下发送。例如,如果用户说“放点音乐”。在这种情况下,应用可以开始播放最近播放的曲目或新曲目。
如果您的应用无法快速处理搜索请求,请勿在 onPlayFromSearch
中屏蔽。
请改为将播放状态设置为 STATE_CONNECTING
,并在异步线程上执行搜索。
开始播放后,请考虑使用相关内容填充媒体会话的队列。例如,如果用户请求播放某个专辑,您的应用可以使用该专辑的曲目列表填充队列。
除了“播放”查询,Android Auto 和 AAOS 还会识别控制播放的语音查询(例如“暂停播放音乐”和“下一首歌”),并将这些命令与相应的媒体会话回调(如 onPause
和 onSkipToNext
)相匹配。
如需详细了解如何实现语音控制播放操作,请参阅 Google 助理和媒体应用。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-22。
[null,null,["最后更新时间 (UTC):2025-08-22。"],[],[],null,["# Support voice actions\n\nIntegrate voice actions into your media app to enhance driver safety and\nconvenience by minimizing distractions. When Android Auto or Android Automotive\nOS (AAOS) detects and interprets a voice action, they deliver the action to your\napp through the `onPlayFromSearch` callback.\n\nUpon receiving the callback, your app finds content that matches the query\nstring and then starts playback. Your app must account for various query\ncategories, such as genre, artist, album, song name, radio station, or playlist.\nAdditionally, your app must handle an empty query string, which indicates a\ngeneral request for music.\n\nIf your app is playing one media item, the user can say \"Play \\[song title\\]\"\nto tell your app to play a different song without looking at or touching the\ncar's display. Users can initiate queries by clicking the appropriate buttons\non their steering wheel or speaking the hotwords \"OK Google.\"\n| **Design guidelines:** To learn more, see [Create apps](/cars/design/create-apps).\n\nWhen Android Auto or AAOS detects and interprets a voice action, Android Auto or\nAAOS delivers that voice action to the app through [`onPlayFromSearch`](/reference/android/support/v4/media/session/MediaSessionCompat.Callback#onPlayFromSearch(java.lang.String,%20android.os.Bundle)). Upon\nreceiving this callback, the app finds content to match the `query` string and\nthen starts playback.\n\nUsers can specify different categories of terms in their query: genre, artist,\nalbum, song name, radio station, or playlist, among others. When building\nsupport for search, account for all the categories that make sense for your app.\nIf Android Auto or AAOS detects that a given query fits into a specific\ncategory, extras are appended in the `extras` parameter. You can send these\nextras:\n\n- [`EXTRA_MEDIA_ALBUM`](/reference/android/provider/MediaStore#EXTRA_MEDIA_ALBUM)\n- [`EXTRA_MEDIA_ARTIST`](/reference/android/provider/MediaStore#EXTRA_MEDIA_ARTIST)\n- [`EXTRA_MEDIA_GENRE`](/reference/android/provider/MediaStore#EXTRA_MEDIA_GENRE)\n- [`EXTRA_MEDIA_PLAYLIST`](/reference/android/provider/MediaStore#EXTRA_MEDIA_PLAYLIST)\n- [`EXTRA_MEDIA_TITLE`](/reference/android/provider/MediaStore#EXTRA_MEDIA_TITLE)\n\nAccount for an empty `query` string, which can be sent by Android Auto or AAOS\nif the user doesn't specify search terms. For example, if the user says\n\"Play some music.\" In this case, your app can start a recently played or new\ntrack.\n\nIf your app can't process a search quickly, don't block in `onPlayFromSearch`.\nInstead, set the playback state to [`STATE_CONNECTING`](/reference/android/support/v4/media/session/PlaybackStateCompat#STATE_CONNECTING()) and perform the\nsearch on an async thread.\n\nWhen playback starts, consider populating the media session's queue with\nrelated content. For example, if the user requests an album to be played, your\napp could fill the queue with the album's tracklist.\n\nIn addition to \"Play\" queries, Android Auto and AAOS recognize voice queries to\ncontrol playback like \"pause music\" and \"next song\" and match these commands to\nthe appropriate media session callbacks, such as `onPause` and `onSkipToNext`.\n\nTo learn more about implementing voice-enabled playback actions, see\n[Google Assistant and media apps](/media/implement/assistant)."]]