I'm trying to display all possible information about vehicle when android auto is connected to my android app.
Unfortunately I get nulls everywhere.
I'm using Desktop Head Unit emulator and actual mobile device. I also tested app on real vehicle, and it showed same results.
Method for getting information:
private fun getData() {
Log.i(TAG, "getData()")
val carService = carContext.getCarService(CarHardwareManager::class.java)
val carInfo = carService.carInfo
val carSensors = carService.carSensors
textMap["Car App Api Level"] = carContext.carAppApiLevel.toString()
textMap["Host info"] = carContext.hostInfo.toString()
textMap["Is dark mode"] = carContext.isDarkMode.toString()
try {
carService.carClimate
textMap["Car climate"] = "Available"
} catch (t: Throwable) {
textMap["Car climate"] = "Unavailable"
}
carSensors.addGyroscopeListener(UPDATE_RATE_NORMAL, carContext.mainExecutor) {
textMap["Gyroscope"] = it.toString()
invalidate()
}
carSensors.addCarHardwareLocationListener(UPDATE_RATE_NORMAL, carContext.mainExecutor) {
textMap["Car Hardware Location"] = it.location.value.toString()
invalidate()
}
carSensors.addCompassListener(UPDATE_RATE_NORMAL, carContext.mainExecutor) {
textMap["Compass"] = it.orientations.value.toString()
invalidate()
}
carSensors.addAccelerometerListener(UPDATE_RATE_NORMAL, carContext.mainExecutor) {
textMap["Accelerometer"] = it.forces.value.toString()
invalidate()
}
carInfo.fetchEnergyProfile(carContext.mainExecutor) {
textMap["Energy Profile"] =
it.fuelTypes.value.toString() + " " + it.evConnectorTypes.value.toString()
invalidate()
}
carInfo.addTollListener(carContext.mainExecutor) {
textMap["Toll Card"] = it.cardState.value.toString()
invalidate()
}
carInfo.addSpeedListener(carContext.mainExecutor) {
textMap["Speed"] =
it.speedDisplayUnit.value.toString() + " " + it.rawSpeedMetersPerSecond.value.toString() + " " + it.displaySpeedMetersPerSecond.value.toString()
invalidate()
}
carInfo.addMileageListener(carContext.mainExecutor) {
textMap["Mileage"] = it.odometerMeters.value.toString()
invalidate()
}
carInfo.addEvStatusListener(carContext.mainExecutor) {
textMap["Ev Status"] =
it.evChargePortConnected.value.toString() + " " + it.evChargePortOpen.value.toString()
invalidate()
}
carInfo.addEnergyLevelListener(carContext.mainExecutor) {
textMap["Energy level"] =
"Battery percent: " + it.batteryPercent.value.toString() +
", Fuel percent: " + it.fuelPercent.value.toString() +
", Distance display unit: " + it.distanceDisplayUnit.value.toString()
", Energy is low: " + it.energyIsLow.value.toString() +
", Fuel volume display unit: " + it.fuelVolumeDisplayUnit.value.toString() +
", Range rmaining meters: " + it.rangeRemainingMeters.value.toString()
invalidate()
}
carInfo.fetchModel(carContext.mainExecutor) {
textMap["Model"] =
"Name: " + it.name.value.toString() +
", Manufacturer: " + it.manufacturer.value.toString() +
", Value: " + it.year.value.toString()
invalidate()
}
}
Why are all fields null and how to fix it?