【问题标题】:Android Auto error : Action strip for this template must be setAndroid Auto 错误:必须设置此模板的操作条
【发布时间】:2022-08-03 01:10:35
【问题描述】:

我最近一直在玩 Android Auto,我目前正在尝试使用 android for cars 库中提供的导航模板制作导航应用程序。我正在尝试在 NavigationScreen 类下使用此模板,但出现以下错误:

...
Caused by: java.lang.IllegalStateException: Action strip for this template must be set
...
        at com.smartherd.mynavapp.NavigationScreen.onGetTemplate(MyNavigationCarAppService.kt:37)
...

这是导航应用服务代码:

package com.smartherd.mynavapp

import android.content.Intent
import androidx.car.app.CarAppService
import androidx.car.app.CarContext
import androidx.car.app.Screen
import androidx.car.app.Session
import androidx.car.app.model.Action
import androidx.car.app.model.ActionStrip
import androidx.car.app.model.CarIcon
import androidx.car.app.model.Template
import androidx.car.app.navigation.model.NavigationTemplate
import androidx.car.app.validation.HostValidator


class MyNavigationCarAppService : CarAppService() {
    override fun createHostValidator(): HostValidator {
        return HostValidator.ALLOW_ALL_HOSTS_VALIDATOR
    }

    override fun onCreateSession(): Session {
        return NavigatorSession()
    }
}

class NavigatorSession() : Session() {
    override fun onCreateScreen(intent: Intent): Screen {
        return NavigationScreen(carContext)
    }
}

class NavigationScreen(carContext: CarContext) : Screen(carContext) {
    override fun onGetTemplate(): Template {
        val panAction: Action = Action.Builder(Action.PAN).setIcon(CarIcon.APP_ICON).build()
        val mapActionStrip = ActionStrip.Builder().addAction(panAction).build()
        val builder = NavigationTemplate.Builder()
        return builder.setMapActionStrip(mapActionStrip).build()
    }

}

    标签: kotlin android-auto android-automotive


    【解决方案1】:

    此外,您需要使用以下方法设置 Action Strip:

    builder.setActionStrip(...)
    

    您现在对setMapActionStrip 所做的几乎相同

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-14
      • 2013-05-15
      • 2016-01-19
      相关资源
      最近更新 更多