我面临的问题是,使用Android Auto时,Google地图为空白。
到目前为止,我所做的事情:
在AndroidManifest.xml文件中添加了Google API密钥。
为Android Auto创建了必要的服务和屏幕。尝试过 同时使用NavigationTemplate和MapWithContentTemplate.在两种情况下,都可以看到小部件(例如按钮,标题等), 但是地图本身是空白的。 我已经检查了Google文档,但似乎已经过时了或 贬低了,我找不到解决方案。
问题:我在Android Auto中缺少Google Maps的特定配置? 在Android Auto中使用Google Maps有任何已知问题或限制?
我应该使用任何替代方法或模板<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="androidx.car.app.NAVIGATION_TEMPLATES"/>
<uses-permission android:name="androidx.car.app.ACCESS_SURFACE" />
<uses-feature android:name="android.hardware.sensor.compass"
android:required="true" />
<uses-feature
android:name="android.hardware.type.automotive"
android:required="true" />
<application
android:allowBackup="true"
android:appCategory="audio"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Testing_navigation">
<!-- Important to show in Android Auto App-->
<meta-data
android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="Google_Map_Key" />
<meta-data
android:name="androidx.car.app.minCarApiLevel"
android:value="7"/>
<service android:name=".MyNavigationService"
android:exported="true">
<intent-filter>
<action android:name="androidx.car.app.CarAppService"/>
<category android:name="androidx.car.app.category.NAVIGATION"/>
</intent-filter>
</service>
</application>
</manifest>
class MyNavigationService : CarAppService() {
override fun createHostValidator(): HostValidator {
return if ((applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
HostValidator.ALLOW_ALL_HOSTS_VALIDATOR
} else {
HostValidator.Builder(baseContext)
.addAllowedHosts(R.array.hosts_allowlist_sample).build()
}
}
override fun onCreateSession(): Session {
return NavigationSession()
}
}
class NavigationSession : Session() {
override fun onCreateScreen(intent: Intent): Screen {
// Navigation Screen
return NavigationScreen(carContext)
// Hello World Screen
// return HelloWorldScreen(carContext)
}
}
// Map Test Code 1
val template = NavigationTemplate.Builder()
.setActionStrip(actionStrip)
.setDestinationTravelEstimate(travelEstimate)
.build()
// Map Test Code 2
val template = MapWithContentTemplate.Builder()
.setLoading(false)
.setContentTemplate(
PaneTemplate.Builder(paneBuilder.build())
.setTitle("Hello")
.build()
)
.setActionStrip(actionStrip)
.setMapController(mapController)
.build()
return template
确保使用
GoogleMaps AndroidApi和android autoApis
启用了Google Maps API键已在Google Cloud控制台中正确设置,并且已启用了可调试的无限制访问。在androidx.car.app.ACCESS_LOCATION
AndroidManifest.xml
。在将其传递给mapController
之前,请验证MapWithContentTemplate
val mapController = MapController.builder()
.setMapActionStrip(actionStrip)
.setPanModeEnabled(true)
.build()
implementation "androidx.car.app:app:1.4.0"
aadd登录在导航中以检查服务是否触发:
Log.d("AndroidAuto", "Creating Navigation Screen")
检查thing thinglogcat
的错误,并使用替代性测试
adb logcat -s AndroidAuto
确认该问题是特定于地图的。如果问题持续存在,请参阅google问题跟踪器
有关已知错误。