Следующие значения приемника вещания должны сообщать вам, когда какое-либо устройство BT отключено:
intentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED); // API 5
intentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED); // API 5
Вам, вероятно, следует реализовать прокси-прослушиватель BluetoothProfile.ServiceListener, если вы заинтересованы в конкретном устройстве:
private class MyBluetoothHeadsetListener //
implements BluetoothProfile.ServiceListener
{
@Override
public void onServiceDisconnected(int profile)
{
}
@Override
public void onServiceConnected(int profile, BluetoothProfile proxy)
{
if (profile == BluetoothProfile.A2DP)
{
BluetoothA2dp bluetoothA2dp = (BluetoothA2dp) proxy;
mDevicesA2dp = bluetoothA2dp.getConnectedDevices();
for (BluetoothDevice deviceA2dp : mDevicesA2dp)
{
boolean isA2dpPlaying = bluetoothA2dp.isA2dpPlaying(deviceA2dp);
}
return;
}
if (profile == BluetoothProfile.HEADSET)
{
BluetoothHeadset bluetoothHeadset = (BluetoothHeadset) proxy;
mDevicesNonA2dp = bluetoothHeadset.getConnectedDevices();
if (mDevicesNonA2dp.size() > 0)
{
for (BluetoothDevice deviceNonA2dp : mDevicesNonA2dp)
{
BluetoothClass bluetoothClass = deviceNonA2dp.getBluetoothClass();
String bluetoothDeviceClass = bluetoothClassToString(bluetoothClass);
boolean isAudioConnected = bluetoothHeadset.isAudioConnected(deviceNonA2dp);
}
}
return;
}
}
}
...
private MyBluetoothHeadsetListener mProfileListener = new MyBluetoothHeadsetListener();
...
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
adapter.getProfileProxy(mApp, mProfileListener, BluetoothProfile.HEADSET);
adapter.getProfileProxy(mApp, mProfileListener, BluetoothProfile.A2DP);