I am trying to check when my device is connected to a car. I assume that the car acts like a Bluetooth headset, so I used the following code in my onCreate activity:
// Get the default adapter BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); BluetoothProfile.ServiceListener mProfileListener = new BluetoothProfile.ServiceListener() { public void onServiceConnected(int profile, BluetoothProfile proxy) { Time today = new Time(Time.getCurrentTimezone()); today.setToNow(); if (profile == BluetoothProfile.HEADSET) { mBluetoothHeadset = (BluetoothHeadset) proxy; LogginUtil.logString("BluetoothApp", "Headset event called at " + today.format("%k:%M:%S") + " - " + profile); } else { LogginUtil.logString("BluetoothApp", "Other event called at " + today.format("%k:%M:%S") + " - " + profile); } } public void onServiceDisconnected(int profile) { if (profile == BluetoothProfile.HEADSET) { mBluetoothHeadset = null; Time today = new Time(Time.getCurrentTimezone()); today.setToNow(); LogginUtil.logString("BluetoothApp", "Headset event disconnected at " + today.format("%k:%M:%S")); } } }; // Establish connection to the proxy. mBluetoothAdapter.getProfileProxy(getApplicationContext(), mProfileListener, BluetoothProfile.HEADSET);
When I launch the application, when turning on and off bluetooth, I get the following output:
Headset event called at "current time" - 1
When I connect my device to the car, I get exactly the same result:
Headset event called at "current time" - 1
What do I need to do to find out that my device is actively connecting via Bluetooth with the car?
Thank you in advance, and let mw know if you need anything else.
PICTURE PICTURE
Just in case, I did not understand my question. I want to receive notifications (log only) when the device enters the state of connecting to the car via Bluetooth. Is this possible?
source share