向模板化应用添加对 Android Auto 的支持
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
请阅读以下信息,了解如何更改应用的清单,使 Android Auto 能够发现应用的 CarAppService
并与之交互。
声明 Android Auto 支持
Android Auto 主机会检查应用是否已声明支持 Android Auto。如需启用此支持,请在应用的清单中添加以下条目:
<application>
...
<meta-data
android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc"/>
...
</application>
此清单条目引用您创建的另一个 XML 文件,其路径为 AppProjectDirectory/app/src/main/res/xml/automotive_app_desc.xml
。
在该文件中,您应对应用支持的 Android Auto 功能进行声明。
使用 Android for Cars 应用库的应用必须在 automotive_app_desc.xml
文件中声明 template
功能:
<automotiveApp>
<uses name="template" />
</automotiveApp>
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-21。
[null,null,["最后更新时间 (UTC):2025-08-21。"],[],[],null,["# Add support for Android Auto to your templated app\n\nReview the following information to learn how make changes to your app's manifest\nso that Android Auto can discover and interact with your app's `CarAppService`.\n\nDeclare Android Auto support\n----------------------------\n\nThe [Android Auto host](/training/cars/apps#key-terms-concepts) checks whether\nthe app has declared support for [Android Auto](/training/cars#auto).\nTo enable this support, include the following entry in your app's manifest: \n\n \u003capplication\u003e\n ...\n \u003cmeta-data\n android:name=\"com.google.android.gms.car.application\"\n android:resource=\"@xml/automotive_app_desc\"/\u003e\n ...\n \u003c/application\u003e\n\nThis manifest entry refers to another XML file that you create with the\npath \u003cvar translate=\"no\"\u003eAppProjectDirectory\u003c/var\u003e`/app/src/main/res/xml/automotive_app_desc.xml`.\nIn that file, you declare what Android Auto capabilities your app supports.\n\nApps using the [Android for Cars App\nLibrary](/reference/androidx/car/app/package-summary)\nmust declare the `template` capability in the `automotive_app_desc.xml` file: \n\n \u003cautomotiveApp\u003e\n \u003cuses name=\"template\" /\u003e\n \u003c/automotiveApp\u003e"]]