I'm sitting with an app and want to try it out for Android Auto. Im using the DHU for emulating the dashboard, but I'm not able to see the layout due to an ANR (Application not responding) error.
I do get one error in the logcat, but I'm unsure if its related to this:
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)
My code is basically this
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
}
}
}
and I've added the necessay tags to the manifest:
<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>