android - Android Auto Dekstop 主机 ANR:GET_APP_VERSION
问题描述
我正在使用一个应用程序并想在 Android Auto 上试用它。我使用 DHU 来模拟仪表板,但由于 ANR(应用程序无响应)错误,我无法看到布局。
我确实在 logcat 中遇到了一个错误,但我不确定它是否与此有关:
2021-03-04 15:36:07.654 19595-19616/com.ooono.app W/Binder: Caught a RuntimeException from the binder stub implementation.
java.lang.SecurityException: Binder invocation to an incorrect interface
at android.os.Parcel.nativeEnforceInterface(Native Method)
at android.os.Parcel.enforceInterface(Parcel.java:650)
at androidx.car.app.ICarApp$Stub.onTransact(ICarApp.java:207)
at android.os.Binder.execTransactInternal(Binder.java:1159)
at android.os.Binder.execTransact(Binder.java:1123)
我的代码基本上是这样的
import android.content.Intent
import android.content.pm.ApplicationInfo
import androidx.car.app.*
import androidx.car.app.model.*
import androidx.car.app.navigation.model.NavigationTemplate
import androidx.car.app.validation.HostValidator
class CarActivity : CarAppService() {
override fun createHostValidator(): HostValidator {
return if (applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE !== 0) {
HostValidator.ALLOW_ALL_HOSTS_VALIDATOR
} else {
HostValidator.Builder(this)
.addAllowedHosts(R.array.hosts_allowlist_sample)
.build()
}
}
override fun onCreateSession(): Session {
return object : Session(){
override fun onCreateScreen(intent: Intent): Screen {
return NavScreen(carContext)
}
}
}
class NavScreen(carContext: CarContext) : Screen(carContext){
override fun onGetTemplate(): Template {
val listTemplate = ListTemplate.Builder().apply {
addSectionedList(SectionedItemList.create(
ItemList.Builder()
.addItem(Row.Builder().setTitle("list 1").addText("hellowrodl").build())
.build(),"List"
))
}
return listTemplate.build()
}
private fun actionStrip():ActionStrip{
val strip = ActionStrip.Builder().apply {
addAction(Action.Builder().setIcon(CarIcon.APP_ICON).setTitle("Ooono").setOnClickListener { }.build())
}.build()
return strip
}
}
}
我已经在清单中添加了必要的标签:
<meta-data
android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc" />
<service
android:name=".aa.CarActivity"
android:label="@string/common_app_name"
android:icon="@mipmap/ic_launcher"
android:foregroundServiceType="location"
android:exported="true">
<intent-filter>
<action android:name="androidx.car.app.CarAppService"/>
<category android:name="androidx.car.app.category.NAVIGATION"/>
</intent-filter>
</service>
解决方案
我有同样的问题。根据您的 Android 手机的新旧程度,您应该有 2 个选项:
- 更改库:
将库从 AndroidX 更改为com.google.android 迁移指南,(只是反语)是降级。AndroidX 提供更多功能并将定期更新 - com.google.android 已关闭。第一印象应该没问题,建议使用 AndroidX 进一步的方法
尝试HelloWorld 演示来检查它的功能
--> 在我的情况下,问题是 Android 9 的“旧”pysicaly 手机,旧库没有任何问题但是AndroidX 没有。
有用的链接:
AndroidX 汽车应用程序库概述
com.google.android 库概述 - 使用新手机 --> Android 10 应该没问题。
我的主要 Android 手机(xiaomi mi note 10 lite - Android 10)和 AndroidX 可以正常工作
推荐阅读
- asp.net-mvc - ASP.NET MVC 分页列表松散复选框列表过滤器
- python - 使用在线 LDA 预测测试数据
- google-maps - 在 PF 对话框中将命名 Bean 变量作为 Primefaces gmap 函数的参数传递
- javascript - Chart.js 不工作 - 未捕获的 ReferenceError:
- angularjs - AngularJS注销不适用于匿名函数
- git - 当我们从 Azure DevOps 拉取源代码时,与 Sync 的不同拉取
- python - 不正确的模式计算还是这是盐和胡椒?
- android - 如何基于 JSON 对象构建 ListView 并在 onItemClick 之后传递其数据
- javascript - 如何实现 IPC 渲染器以调整电子窗口的大小
- angular - 在角度 6 单元测试中找不到 [formGroup]