0

In my Android Auto projection-type app I am trying to get info on the car I am attached to. Preferably manufacturer or other VHAL type parameters. Speed, tach, gear position etc would be nice too.

Is this possible in Android Auto?

I tried:

car = Car.createCar(getCarContext());
CarInfoManager carInfoManager = (CarInfoManager) car.getCarManager(Car.INFO_SERVICE);

but I get an exception on Car.createCar

I am trying this code in the onCreateSession in the CarAppService with no luck

Uberbug
  • 97
  • 9

1 Answers1

0

Two previous answers to my question from other people got deleted. No idea why, but they gave me the hints I needed to fix the code and get it working.

in the CarAppService implementation, in the

public Session onCreateSession() {

at the end where I do:

return new Session() {

I have a block of code like this:

  CarInfo carInfo = 
  getCarContext().getCarService(CarHardwareManager.class).getCarInfo();

  mCarHardwareExecutor = ContextCompat.getMainExecutor(getCarContext());

  OnCarDataAvailableListener<Model> mModelListener = data -> {
    synchronized (this) {

    String statusText = "" + data.getYear().getValue() + " " + data.getManufacturer().getValue() + " " + data.getName().getValue();
    theSimpleAAScreen.setStatusText(statusText);
    theSimpleAAScreen.invalidate();
  }

  /* get year, make, model */
  try {
    carInfo.fetchModel(mCarHardwareExecutor, mModelListener);
  } catch (SecurityException e) {
    Log.e(TAG, "No permission to get model");
  }

theSimpleAAScreen is an object that is the android auto screen: I set a value for what to print and invalidate the screen so it redraws. There is probably a better / smoother way but this works and answers my question.

Uberbug
  • 97
  • 9