I have an app that doesn’t have any Android Auto/CarPlay features; in other words, it’s an ordinary app that wasn’t made to run on Android Auto/CarPlay.
With the code below, I thought I could detect when the user connects to Android Auto/CarPlay, but that didn’t happen.
Is there a way to know if the user is connected to Android Auto/CarPlay?
carModeReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
val action = intent?.action
if (action == Intent.ACTION_DOCK_EVENT) {
val dockState = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, -1)
if (dockState == Intent.EXTRA_DOCK_STATE_CAR) {
updateStatus("Connected to Android Auto/CarPlay")
} else {
updateStatus("Not in car")
}
}
}
}