google地图在AndroidAuto

问题描述 投票:0回答:1

我面临的问题是,使用Android Auto时,Google地图为空白。 到目前为止,我所做的事情:Desktop Head Unit [Test Code 1 Output]

在AndroidManifest.xml文件中添加了Google API密钥。

为Android Auto创建了必要的服务和屏幕。尝试过 同时使用NavigationTemplate和MapWithContentTemplate.

在两种情况下,都可以看到小部件(例如按钮,标题等), 但是地图本身是空白的。 我已经检查了Google文档,但似乎已经过时了或 贬低了,我找不到解决方案。

问题:
  1. 即使其余的UI(小部件,模板等)效果很好,该地图也没有在Android Auto中呈现。
  2. IT似乎是Google Maps集成的运行不如预期的,我不确定这是否是由于对API的不良配置,弃用的API或其他内容。
  3. 我需要帮助:

我在Android Auto中缺少Google Maps的特定配置? 在Android Auto中使用Google Maps有任何已知问题或限制?

我应该使用任何替代方法或模板
    是为Android Auto弃用的Google Maps集成,如果是,建议的替代方案是什么?
  1. android清单:

<?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>

服务:
  1. 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) } }
  2. 屏幕模板:
  3. // 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()
android google-maps google-maps-api-3 android-auto android-automotive
1个回答
0
投票

implementation "androidx.car.app:app:1.4.0" aadd登录在导航中以检查服务是否触发: Log.d("AndroidAuto", "Creating Navigation Screen") 检查thing thinglogcat

的错误,并使用替代性测试
adb logcat -s AndroidAuto
确认该问题是特定于地图的。如果问题持续存在,请参阅
google问题跟踪器
有关已知错误。
    

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.