天气应用允许用户查看与他们当前位置或沿途相关的天气信息。天气应用还可以提供导航功能,请参阅为汽车构建导航应用了解构建导航应用的更多详细信息。
在你的清单中声明天气类别
你的应用必须在其CarAppService
的 Intent 过滤器中声明 androidx.car.app.category.WEATHER
车载应用类别。
<application>
...
<service
...
android:name=".MyCarAppService"
android:exported="true">
<intent-filter>
<action android:name="androidx.car.app.CarAppService" />
<category android:name="androidx.car.app.category.WEATHER"/>
</intent-filter>
</service>
...
<application>
声明导航支持
如果你的应用也可以用于导航,则在声明其类别时,它还必须遵循在你的清单中声明导航支持中找到的指南。用于声明应用类别的 Intent 过滤器应包含这两种类别
<intent-filter>
<action android:name="androidx.car.app.CarAppService" />
<category android:name="androidx.car.app.category.WEATHER"/>
<category android:name="androidx.car.app.category.NAVIGATION"/>
</intent-filter>
实现你的应用功能
要实现你的应用,请参阅使用车载 Android 应用库了解车载应用库应用是如何构建的。此外,请务必熟悉天气应用的车载应用质量指南,因为你的应用将根据这些指南进行审核。
绘制地图
天气应用可以访问MapWithContentTemplate
,它可以用于显示列表和其他类型的内容以及由你的应用渲染的地图。请参阅绘制地图了解使用此模板的更多详细信息。
要访问该模板,你的应用需要在其 AndroidManifest.xml
文件中声明 androidx.car.app.MAP_TEMPLATES
或 androidx.car.app.NAVIGATION_TEMPLATES
权限
<manifest ...>
...
<!-- Use the MAP_TEMPLATES permission if your app doesn't provide navigation functionality -->
<uses-permission android:name="androidx.car.app.MAP_TEMPLATES"/>
<!-- Use the NAVIGATION_TEMPLATES permission if your app provides navigation functionality -->
<uses-permission android:name="androidx.car.app.NAVIGATION_TEMPLATES"/>
...
</manifest>