Search code examples
androidbluetooth-lowenergybroadcastreceiverobd-ii

How to Implement Automatic OBD2 Connection with Android Without Constant Foreground Service


Scenario: The Android and OBD2 devices are paired, and the app is in a state where the task is killed (the process is not completely dead). For example, when you get into the car, the OBD2 and the Android device start connecting without using the app, and this connection is detected by a broadcast receiver, which then starts the service via the app.

There is an app in the market that works this way. How is this implemented?

Since no notifications are received, it does not seem like a foreground service is always running.

Questions: When the OBD2 device is powered on, does the automatic connection between the Android device and OBD2 depend on the settings of the OBD2 device? Is it possible to achieve an automatic connection during the initial connection flow via the app, so that the devices connect automatically thereafter?

Since Android 12, when starting a foreground service from the background, a ForegroundServiceStartNotAllowedException occurs. I also want to know how to handle this issue.

Since the OBD2 device is already paired, I thought it would automatically connect with the OS without needing the app. However, after killing the app task, the OBD2 did not reconnect.

I want to create an app that allows the OBD2 and Android device to start connecting when I get into the car, without using the app. I don't know how to achieve this. Please help.


Solution

  • I suspect that the operating system didn't automatically connect via BLE because a paired OBD2 device was nearby. Instead, when you get in the car, a different BLE device, not the OBD2, emits a beacon, and the smartphone catches that beacon and launches the app.

    I've concluded that automatic OBD2 connection is not feasible.

    Thank you.