Car App:CarPlay和Android Auto开发的本质

作者: IT Sectr 发布日期: 2026-02-15 阅读时间: 9 分钟

Car App — 用于车载信息娱乐系统的应用程序,可与Apple CarPlay和Android Auto集成。CarPlay是苹果的技术,将iPhone界面投射到汽车屏幕上,可通过Siri、触摸屏或方向盘按钮控制。Android Auto是谷歌针对Android智能手机的类似技术。Car App开发包括:用Swift配合CarPlay框架和SiriKit为iOS创建应用,用Kotlin配合Car App库、MediaBrowserService和NavigationManager为Android创建应用。Car App支持正成为现代汽车的标准——据苹果称,美国98%的新车支持CarPlay,Android Auto在200多款车型上可用。

要点

  • Car App — 为CarPlay(iOS)和Android Auto(Android)优化的驾驶时使用的应用程序
  • Apple CarPlay — 将iPhone界面投射到汽车屏幕,通过Siri和触摸控制
  • Android Auto — 将Android智能手机投射到汽车屏幕,支持Google Assistant
  • CarPlay框架 — CPInterfaceController、CPTemplate、CPListItem用于在Swift中构建界面
  • Car App库 — 用于创建Automotive应用的Android库,支持MediaBrowserService和NavigationManager

什么是Car App

Car App — 是通过智能手机投影在车载信息娱乐系统(IVI)中运行的应用程序——iOS用Apple CarPlay,Android用Android Auto。与Android Automotive OS(内置于汽车的操作系统)不同,CarPlay和Android Auto是移动应用的扩展,在手机上运行并将界面投射到汽车屏幕。Car App是您现有的iOS/Android应用,实现了CarPlay或Android Auto协议。

Car App的关键类别:导航(Apple Maps、Google Maps、Waze、Sygic)、音频(Spotify、Apple Music、YouTube Music、Audible、Castbox)、消息(通过Siri/Google Assistant朗读和听写)、汽车功能(EV充电、停车、汽车状态)、VOIP通话(WhatsApp、Zoom)。每个类别都有自己的界面模板——ListTemplate、MapTemplate、AudioTemplate。系统根据注册的Intents自动确定应用支持哪个类别。

Car App的限制:苹果和谷歌严格管控UX以确保安全——最少元素数量、大按钮(至少48x48 pt)、无文本输入(仅语音)、行驶时界面自动变暗、禁止视频。触摸响应时间必须小于100毫秒。所有应用必须经过强制审核(CarPlay需App Review,Android Auto需Google Play Console + CTS)。

Apple CarPlay:CarPlay框架和SiriKit

CarPlay框架(原名CPKit)——苹果用于在Swift中创建CarPlay应用的框架。关键类是CPInterfaceController,它管理模板间的导航。CPInterfaceController包含模板栈:CPListTemplate(列表)、CPMapTemplate(导航)、CPNowPlayingTemplate(音频)、CPVoiceControlTemplate(语音控制)。CPListTemplate包含CPListItem——带有图标、文本和操作的列表项。

用于CarPlay的SiriKit——SiriKit扩展,用于在车内通过语音控制应用。应用注册Intents(INPlayMediaIntent — 播放、INStartWorkoutIntent — 锻炼、INSendMessageIntent — 消息)。CarPlay连接时Siri自动激活,可通过方向盘上的语音控制按钮访问。SiriKit CarPlay支持CarPlay Dashboard——CarPlay主屏幕上的小部件,用于显示应用信息(目的地、当前曲目)。

CarPlay连接过程:iPhone通过Lightning/USB-C线缆或无线方式(CarPlay Wireless,从iOS 9开始)连接汽车。连接后,如果应用实现了CPApplicationDelegate,iOS会自动启动CarPlay会话。开发者不管理连接时机——系统在会话开始和结束时调用delegate方法。CarPlay支持多任务处理:切换音乐时导航在后台运行,语音提示继续发声。

Android Auto:Car App库

Android Car App库——用于创建与Android Auto兼容应用的Android库。基础组件:CarAppService — Android Auto的入口点;Session — 管理会话生命周期;Screen — 应用的每个屏幕;CarScreenManager — 管理显示。应用支持MediaBrowserService用于媒体内容,NavigationManager用于导航提示。

MediaBrowserService——音频应用的关键组件。应用实现MediaBrowserService和MediaSession来管理播放。Android Auto自动显示控制按钮(播放/暂停、下一首、上一首)和曲目列表。NavigationManager用于导航应用——传递转弯指令、路线状态和警报。NavigationManager支持CarNotification,在Android Auto状态栏中显示导航提示。

Android Auto要求:应用必须在清单中具有category="android.intent.category.APP_AUTO";必须使用AndroidX,最低SDK 26+;支持深色主题(DayNight);支持触摸和语音控制;符合Android Auto Compatibility Test Suite(CTS)要求。Google Play检查每个应用是否符合安全和UX要求。认证过程需要1-4周。

代码示例:Swift和Kotlin

使用CarPlay框架在Swift中为CarPlay开发的导航应用示例。

swift
import CarPlay

class CarPlaySceneDelegate: CPTemplateApplicationSceneDelegate {

    func templateApplicationScene(
        _ templateApplicationScene: CPTemplateApplicationScene,
        didConnect interfaceController: CPInterfaceController
    ) {
        let searchItem = CPListItem(
            text: "搜索地址",
            detailText: "输入目的地"
        )
        searchItem.handler = { _, completion in
            // 打开搜索屏幕
            completion()
        }

        let favoritesItem = CPListItem(
            text: "收藏",
            detailText: "已保存的地址"
        )
        favoritesItem.handler = { _, completion in
            showFavorites()
            completion()
        }

        let section = CPListSection(items: [searchItem, favoritesItem])
        let listTemplate = CPListTemplate(
            title: "导航",
            sections: [section]
        )

        interfaceController.setRootTemplate(listTemplate, animated: true)
    }

    func showFavorites() {
        // 显示收藏地址列表
    }
}

// 用于语音控制的SiriKit Intent
class NavigationIntentHandler: NSObject, INSearchForMessagesIntentHandling {
    func handle(intent: INSearchForMessagesIntent,
                completion: @escaping (INSearchForMessagesIntentResponse) -> Void) {
        // 通过Siri处理语音命令
        let response = INSearchForMessagesIntentResponse(
            code: .success, userActivity: nil
        )
        completion(response)
    }
}

要点:CPTemplateApplicationSceneDelegate — CarPlay会话的入口点;CPInterfaceController管理模板栈;CPListTemplateCPListItem — 基本UI组件;.handler — 每个列表项的触摸处理器。

使用Car App库在Kotlin中为Android Auto开发的导航应用示例:

kotlin
// CarAppService — Android Auto的入口点
class NavigationCarAppService : CarAppService() {
    override fun createSession(): Session = NavigationSession()
}

// Session — 管理会话生命周期
class NavigationSession : Session() {
    override fun onCreateScreen(manager: ScreenManager): Screen {
        return MainScreen(carContext)
    }
}

// MainScreen — 带导航的主屏幕
class MainScreen(carContext: CarContext) : Screen(carContext) {
    override fun onGetTemplate(): Template {
        val searchAction = Action.Builder()
            .setTitle("搜索地址")
            .setOnClickListener { showSearchScreen() }
            .build()

        val favoritesAction = Action.Builder()
            .setTitle("收藏")
            .setOnClickListener { showFavorites() }
            .build()

        return ListTemplate.Builder()
            .setTitle("导航")
            .setHeaderAction(Action.APP_ICON)
            .addAction(searchAction)
            .addAction(favoritesAction)
            .build()
    }

    private fun showSearchScreen() {
        screenManager.push(SearchScreen(carContext))
    }

    private fun showFavorites() {
        screenManager.push(FavoritesScreen(carContext))
    }
}

// AndroidManifest — 服务注册
<service
    android:name=".NavigationCarAppService"
    android:exported="true">
    <intent-filter>
        <action
            android:name="androidx.car.app.action.NAVIGATION" />
    </intent-filter>
    <category
        android:name="android.intent.category.APP_AUTO" />
</service>

要点:CarAppService — Android Auto的入口点;Session — 生命周期管理;Screen — 应用的每个屏幕,返回Template;ListTemplate — 带有Action的列表模板;category.APP_AUTO — 清单中的强制类别。

要求与发布

Apple CarPlay要求:应用必须符合CarPlay Distraction Design Guidelines — 按钮最小尺寸48x48 pt,文字对比度4.5:1,无动画和视频,支持VoiceOver。发布——通过App Store Connect,应用经过苹果标准审核。需要在App Store Connect中指定CarPlay支持并附上CarPlay界面截图。CarPlay应用不能无广告免费——苹果对应用内购买收取30%(小企业15%)的佣金。

Android Auto要求:应用必须符合Android Auto Design Guidelines并通过Android Auto Compatibility Test Suite(CTS)。发布——通过Google Play Console,需要在兼容设备列表中指定"Android Auto"类别。Google Play检查:深色主题支持(DayNight)、连接丢失时的正确行为、屏幕旋转处理、通过Google Assistant的语音控制支持。Android Auto应用不需要额外佣金——标准Google Play模式(15-30%)。

参数Apple CarPlayAndroid Auto
框架CarPlay框架 (CPInterfaceController)Car App库 (CarAppService)
语言SwiftKotlin
语音助手SiriKitGoogle Assistant
界面CPListTemplate, CPMapTemplateListTemplate, MapTemplate
媒体MPNowPlayingInfoCenterMediaBrowserService
导航CPNavigationSessionNavigationManager
发布App Store ConnectGoogle Play Console
佣金15–30%15–30%
审核App Review (1–3天)CTS + Google Play (1–4周)

无线连接支持:CarPlay Wireless从iOS 9开始可用,需要Wi-Fi +蓝牙。Android Auto Wireless从Android 11开始可用。无线连接需要汽车支持相应标准。开发者无需编写额外代码——操作系统自动处理连接。

常见问题

Car App与移动应用有何不同?

Car App针对驾驶使用进行了优化:最少元素数量、大按钮、语音控制、无文本输入。应用必须符合安全要求——苹果和谷歌的Distraction Design Guidelines

CarPlay支持哪些应用类别?

CarPlay支持的类别:导航(Apple Maps、Google Maps、Waze)、音频(Spotify、Apple Music)、消息(通过Siri朗读和听写)、汽车功能(EV充电、停车)和VOIP通话。

如何为Android Auto开发应用?

使用Android Car App库:实现CarAppService作为入口点,Session用于生命周期管理,Screen用于每个屏幕。应用必须支持MediaBrowserService用于媒体或NavigationManager用于导航。

Car App需要审核吗?

是的,两个平台都需要审核。苹果通过App Review审核CarPlay应用。Android Auto需要通过Android Auto Compatibility Test Suite(CTS)和Google Play Console的检查。

Car App使用哪些编程语言?

CarPlay使用Swift配合CarPlay框架(CPInterfaceController、CPTemplate、CPListItem)和SiriKit。Android Auto使用Kotlin配合Car App库和MediaBrowserService。

总结

  • Car App — 为CarPlay(iOS)和Android Auto(Android)优化的安全驾驶使用的应用程序
  • Apple CarPlay使用CarPlay框架配合CPInterfaceController、CPListTemplate和SiriKit进行语音控制
  • Android Auto使用Car App库配合CarAppService、Session、Screen和MediaBrowserService处理媒体
  • 语音控制— Siri(CarPlay)和Google Assistant(Android Auto)是导航和消息的强制要求
  • UX限制— 大按钮48x48 pt、最少元素、禁止视频、响应时间低于100毫秒
  • 审核— App Store(1-3天)和Google Play CTS(1-4周),含安全性和UX检查
  • 无线连接— CarPlay Wireless(iOS 9+)和Android Auto Wireless(Android 11+)无需线缆

我们将开发一款交钥匙移动应用程序

IT Sectr自2017年以来为初创企业和企业打造iOS和Android应用程序。我们将为您提供咨询并提出最佳解决方案。

讨论项目

另请阅读