跳过主要内容
返回插件
@capgo/capacitor-auto
教程
@capgo/capacitor-auto

Auto

桥接 Capacitor 应用程序与 CarPlay 和 Android Auto 模板表面,用于双向汽车通信

指南

CarPlay 和 Android Auto 自动教程

使用 @capgo/capacitor-auto 连接一个 capgo 应用程序到已批准的 CarPlay 和 Android Auto 模板表面。您的应用程序将一个小型列表模板发送到汽车显示屏,汽车显示屏将选定的动作发送回 JavaScript。

@capgo/capacitor-auto connects a Capacitor app to approved CarPlay and Android Auto template surfaces. Your app sends a small list template to the car display, and the car display sends selected actions back to JavaScript.

Capacitor

安装和同步

npm install @capgo/capacitor-auto
npx cap sync

将模板发送到汽车

import { Auto } from '@capgo/capacitor-auto';

await Auto.setRootTemplate({
  title: 'Garage',
  sections: [
    {
      header: 'Doors',
      items: [
        {
          id: 'open-main-door',
          title: 'Open main door',
          subtitle: 'Tap to send the action to the phone app',
          payload: { doorId: 'main' },
        },
      ],
    },
  ],
});

监听驾驶员操作

await Auto.addListener('carAction', async (event) => {
  if (event.id === 'open-main-door') {
    await openGarageDoor(event.payload?.doorId);
  }
});

监视连接状态

const status = await Auto.isAvailable();
console.log(status.available, status.connected, status.platform);

await Auto.addListener('connectionChanged', (event) => {
  console.log('Car connected:', event.connected, event.platform);
});

iOS要求

CarPlay需要为您的应用程序类别获取苹果批准的许可。将CarPlay场景配置添加到 iOS设置文档 并将您的汽车UI保留在苹果批准的模板中。

Android要求

Android Auto使用AndroidX Car App Library。插件包含一个 CarAppService声明了 template 能力,并默认为 IOT category. 评审 Android 设定文档 如果您的应用程序需要另一个 Android Auto 类别,请

设计指南

使用汽车表面进行短期、可预测的操作:

  • 状态行
  • 一键命令
  • 驾驶员安全确认
  • 从手机应用程序简单地传递状态

在手机 UI 中保留复杂流程并使用 carAction 事件作为本机意图触发器。

继续使用 @capgo/capacitor-auto

如果您正在使用 使用@capgo/capacitor-auto 来规划原生媒体和界面行为,连接它与 @capgo/capacitor-auto 的实现细节在@capgo/capacitor-auto中 开始使用 实现细节在开始使用中 使用@capgo/capacitor-live-activities 原生能力在使用@capgo/capacitor-live-activities中 @capgo/capacitor-live-activities 实现细节在@capgo/capacitor-live-activities中,和 使用@capgo/capacitor-video-player 为原生能力在使用 @capgo/capacitor-video-player。