实现导航应用 intent

Gemini 和 Google 助理使用导航应用可支持的三种不同格式的 intent。您可以通过在应用清单中声明本页中详述的 intent 过滤器,实现互操作性并将应用与 Gemini 或 Google 助理集成。如需详细了解 intent,请参阅 Intent。

Gemini 或 Google 助理导航应用 Intent 类支持以下 intent:

  • 导航 intent
  • 搜索意图
  • 自定义操作 intent

intent 数据流

图 1. 意图数据流。

intent 数据中的参数

intent 数据遵循 URI 格式,其中包含基于您要传递的 intent 的参数。某些参数始终在数据中提供。这意味着,您可以预期它们始终具有显式值。不过,可选参数在数据中不一定有值。 如需了解详情,请参阅数据测试。

线下意向

此页面中列出的所有 intent 都有其离线变体。 您可以通过在其架构中附加 .offline 来区分它们。例如,导航 intent 使用 geo.offline 架构。 清单中的这些 intent 过滤器表示应用能够离线支持这些操作。

使用导航 intent 来满足用户导航到特定目的地的请求。此目的地可以是单个地点(地址),也可以是多个地点(例如咖啡店和加油站)。 intent 数据遵循为每个 intent 指定的 URI 格式。

意向格式

Intent 类对导航应用 intent 使用以下格式:

类别:android.intent.category.DEFAULT

操作:

  • Android Auto 和 Android Automotive OS: androidx.car.app.action.NAVIGATE
  • 其他设备类型: android.intent.action.NAVIGATE

Scheme:geo

示例:

  • geo:0,0?q=Googleplex
  • geo:0,0?q=1600+Amphitheatre+parkway&mode=b&intent=add_a_stop
  • geo:0,0?q=coffee+shop&mode=w&intent=navigation
  • geo:1.1,2.2?q=Starbucks+on+Main+Street&mode=w&intent=navigation

建议的应用行为:开始导航到指定位置,或要求用户从多个选项中进行选择。

清单 intent 过滤器

在应用的清单文件中声明以下 intent 格式,以便 Gemini 或 Google 助理知道您的导航应用可以接收导航 intent。

除 Android Auto 和 Android Automotive OS 之外的所有设备规格:

<intent-filter>
  <action android:name="android.intent.action.NAVIGATE" />
  <category android:name="android.intent.category.DEFAULT"/>
  <data android:scheme="geo" />
</intent-filter>

Android Auto 和 Android Automotive OS:

<intent-filter>
  <action android:name="androidx.car.app.action.NAVIGATE" />
  <category android:name="android.intent.category.DEFAULT"/>
  <data android:scheme="geo" />
</intent-filter>

提供的参数

以下参数应在提供的导航应用 intent 数据中提供。

位置查询或地理坐标

每个导航 intent 查询都包含以下一个或两个参数,具体取决于所请求的数据类型:

  • 位置信息查询

    指用户尝试导航到的位置。使用此数据解析用户的目的地。

    参数键:q
    值:用户查询的目的地。

    示例:geo:0,0?q=Golden+Gate+Bridge
    解读:用户想要导航到金门大桥。

  • 地理坐标(纬度和经度)

    指用户用于导航的具体坐标。

    参数键:geo:lat,long
    值:用户查询的坐标。

    示例:geo:1.1,2.2?mode=w&intent=navigation
    解读:用户想要导航到坐标 (1.1, 2.2)。

可选参数

本部分介绍了导航应用 intent 数据中提供的可选参数。

Intent

定义用户意图。如果未设置此参数,则默认用户意图会被视为 navigation。

参数键:intent
可能的值:

  • navigation [默认值] - 替换目的地并开始导航。此 intent 适用于导航到 x 等查询。
  • add_a_stop - 将经停点与之前的目的地一起添加为下一个目的地。对于在 x 处添加经停点等查询,请使用此 intent。
  • directions - 显示路线,但不启动导航。此意图适用于前往 x 的路线等查询。

示例:geo:47.61594547836694,-122.20373173098756?q=575+Bellevue+Square,+Bellevue,+WA+98004&intent=add_a_stop 解读:用户希望在 Bellevue Square, Bellevue 添加一个经停点,当前坐标为 [47.6, -122.2]。

避免

定义导航中要避开的事项。

参数键:avoid
可能的值:

  • f - 轮渡
  • h - 高速公路
  • t - 通行费

示例:geo:0,0?q=googleplex&avoid=tf
解读:用户希望在避开收费路段和轮渡的情况下导航到 Googleplex。

出行模式

出行方式表示用户在查询中指定的交通方式。

参数键:mode
可能的值:

  • b - 自行车
  • d - 云端硬盘
  • x - 出租车
  • l - 双轮机动车
  • r - 公交
  • w - 步行

示例:geo:0,0?q=Googleplex&mode=r
解读:用户想要乘坐公共交通工具前往 Googleplex。

条目

用于记录条目的来源。

可能的值:assistant

示例: geo:47.61594547836694,-122.20373173098756?entry=assistant

搜索意图

使用搜索意图搜索查询,并在驾车时沿路线显示多个结果。

Intent 格式

Intent 类对搜索意图使用以下格式:

类别:android.intent.category.DEFAULT

操作:android.intent.action.VIEW

Scheme:geo

示例: geo:0,0?q=restaurants+nearby

建议的应用行为:打开符合用户查询条件的地点列表。

清单 intent 过滤器

在应用的清单文件中声明以下 intent 格式,以便 Gemini 或 Google 助理知道您的导航应用可以接收搜索 intent:

<intent-filter>
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.DEFAULT"/>
  <data android:scheme="geo" />
</intent-filter>

提供的参数

以下参数应在提供的搜索意图数据中提供。

位置信息查询

位置查询是指用户在驾车时搜索的位置。此查询可能不精确,也可能沿有效导航路线进行。

参数键:q
值:用户的搜索字词,可以是地点类型(例如咖啡店或大学),也可以包含限定词(例如我附近的或评分最高的)。

示例:geo:0,0?q=restaurants+nearby
解读:用户想要搜索附近的餐厅。

自定义操作 intent

使用自定义 intent 执行自定义操作,例如报告事故和结束导航。主要操作类型由 act 查询参数定义。您可以根据操作类型设置其他参数。

意向格式

Intent 类对自定义操作 intent 使用以下格式:

类别:android.intent.category.DEFAULT

操作:android.intent.action.VIEW

Scheme:geo.action

示例: geo.action:?act=report&accident_type=major

清单 intent 过滤器

在应用的清单文件中声明以下 intent 格式,以便让 Gemini 或 Google 助理知道您的导航应用可以接收自定义操作 intent。

<intent-filter>
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.DEFAULT"/>
  <data android:scheme="geo.action" />
</intent-filter>

提供的参数

提供的自定义操作 intent 数据中应包含以下参数:

操作类型

它定义了用户想要执行的自定义操作的类型。

参数键:act

示例:

  • geo.action:?act=report_crash&accident_type=major
    解读:用户想要报告重大事故。

  • geo.action:?act=mute
    解读:用户希望将语音指令静音。

  • geo.action:?act=exit_navigation
    解读:用户想要退出当前导航。

建议的应用行为:在导航应用中执行请求的操作,或显示操作不受支持的消息。

下图展示了响应查询中的键值对示例:

自定义操作 intent 数据流

图 2. 自定义操作 intent 数据流。

键值对:

"act": "report_crash"
"road_direction": other_side"

每个自定义操作始终有一个 act 参数作为键。在上述示例代码中,某些操作可以具有额外的键值对。例如,act=report_crash 支持以下额外键:accident_type 和 road_direction。

键 accident_type 可支持两个值:minor 和 major。

可能的值

下表列出了 Gemini 或 Google 助理可以传递的可能值,这些值表示用户尝试在导航应用中执行的操作。

值 说明 可选参数键 可选参数值
allow_ferries 更改路线偏好设置以允许轮渡。
allow_highways 更改路线偏好设置,允许走高速公路。
allow_tolls 更改路线偏好设置,允许收费路段。
avoid_ferries 更改路线偏好设置以避开轮渡。
avoid_highways 更改路线偏好设置以避开高速公路。
avoid_tolls 更改路线偏好设置以避开收费路段。
distance_to_destination 显示到目的地的距离。
distance_to_next_turn 显示到下一个转弯处的距离。
eta 显示到达目的地所需的预计时间。
exit_navigation 退出或取消导航。
follow_mode 将地图视图更改为跟随模式。
go_back 返回上一个地图操作。
hide_satellite 更改地图设置以隐藏卫星信息。
hide_traffic 更改地图设置以隐藏路况信息。
mute 关闭语音导航。
query_current_road 显示用户当前所在的道路。
query_destination 显示目的地。
query_next_turn 显示下一个转弯。
report_crash 报告崩溃问题。 accident_type minor
major
road_direction this_side
other_side
report_hazard 报告危险路况。 hazard_type animal
broken_traffic_light
construction
flooding
fog
hail
ice
missing_sign
object_on_road
pothole
roadkill
snow
vehicle
weather
road_direction this_side
other_side
location_on_road on_road
on_shoulder
report_police 报告警方行动。 road_direction this_side
other_side
report_road_closure 报告封路情况。 road_closure_type partial
full
report_traffic 报告交通拥堵。 traffic_type moderate
heavy
standstill
road_direction this_side
other_side
route_overview 显示路线概览。
show_alternates 显示备选路线。
show_directions_list 显示精细导航路线。
show_satellite 在地图上显示卫星信息。
show_traffic 在地图上显示路况。
time_to_destination 显示到达目的地所需的预计时间。
time_to_next_turn 显示到达下一个转弯处的预计到达时间。
unmute 取消语音导航静音。

检索导航状态(仅限 Gemini)

为确保 Gemini 能够在用户询问行程状态时提供准确的实时信息,您的应用必须使用 NavigationManager 汽车服务提供导航元数据。具体而言,您的应用需要提供相应功能,并征得用户同意,才能使用 NavigationManager.setVoiceAssistantCapabilities 与 Gemini 分享信息。如需了解实现指南,请参阅传达导航元数据。