1

Ive looked everywhere for a solution to read RPM data on Android Auto with Android studio. Found no solution. I was hoping someone has more experience in this field and could point me in the right direction.

I tried to use CarHardwareManager and looked into CarPropertyManager but I cannot find any proper documentation on how to implement an RPM listener of some sort.

My end goal is to have a listener that will receive the current RPM the vehicle is at.

Please help! Thank you!

Alex
  • 11
  • 3
  • Android Auto is for UI / media (or for car manufacturers). Automotive performance data will require third-party hardware and an app that supports OBD like https://github.com/fr3ts0n/AndrOBD – Morrison Chang Jan 28 '23 at 01:31
  • 1
    @MorrisonChang that's incorrect: https://android-developers.googleblog.com/2021/07/accessing-car-hardware-apis-in-your-app.html – Ryan M Jan 28 '23 at 04:04
  • @RyanM Thanks for the correction. Android Auto and Android Automotive OS branding confuses me. – Morrison Chang Jan 28 '23 at 04:42
  • Did you work out the answer to your question because I'm interested in the answer plus whatever it is you are working on – anihilnine May 29 '23 at 06:54

1 Answers1

1

There is this function that you can use to get properties. CarPropertyManager.getProperty()

You need to use constants defined in VehiclePropertyIds. Here goes the one that could do the trick: VehiclePropertyIds.ENGINE_RPM. Note that this requires certains permissions.

Also the function seems to take a areaId argument. It's a little confusing but using CarPropertyManager.getAreaId(ENGINE_RPM, VEHICLE_AREA_TYPE_WHEEL) may yield the required value. Please double-check it as I cannot test it myself.

CarPropertyManager.getProperty(propertyId, areaId). This should return a CarPropertyValue. Then you can use getValue().

As for the listener, you may implemented this interface to listen for changes in such properties. CarPropertyManager.CarPropertyEventCallback

CarPropertyManager.registerCallback(callback, propertyId, refreshRate)

I'll link to registerCallback documentation https://developer.android.com/reference/android/car/hardware/property/CarPropertyManager#registerCallback(android.car.hardware.property.CarPropertyManager.CarPropertyEventCallback,%20int,%20float)

Brian Alex
  • 125
  • 1
  • 10
  • Thanks for the quick response! How do i know which gradle dependency the CarPropertyManager is included in? I currently have... implementation 'androidx.car.app:app-automotive:1.2.0' but it does not include the CarPropertyManager. It seems that there is very little information on this topic online too. Google isn't bringing up any useful information on this. – Alex Jan 29 '23 at 01:48
  • You're welcome! Yes, it seems that there's few information about this topic. This post might be helpful on how to access CarPropertyManager. https://stackoverflow.com/a/65881218/19166078 – Brian Alex Jan 29 '23 at 02:18
  • It looks like only Android Automotive OS is able to receive the RPM data. However, there is an accelerometer within androidx.car which would give me similar data I could use. I would need to know when the driver lets off the gas pedal and trigger an event. Do you know of how I could possibly implement this? – Alex Jan 29 '23 at 03:56
  • Sorry. No, unfortunately I'm not sure you can replace RPM info with g-forces data from the accelerometer. I'm not a car technician nor a mechanical engineer but I think g-forces have not much to do with an engine RPM. – Brian Alex Feb 03 '23 at 19:29