I have an application that will listen for voice input through bluetooth if available and if not available then will read through the phone microphone. I can't seem to find a way to check if their are any bluetooth devices already connected (not just paired). Any suggestions?
Asked
Active
Viewed 5,063 times
4
-
Have you got the solution for this. I am searching for same, Please provide answer. – Gangadhar Nimballi Nov 16 '15 at 10:13
-
No sorry, i never got a solution. – user2812299 Nov 16 '15 at 13:43
3 Answers
2
The following worked for me (API >= 18):
final BluetoothManager bluetoothManager = (BluetoothManager)getSystemService(Context.BLUETOOTH_SERVICE);
List<BluetoothDevice> gattServerConnectedDevices = bluetoothManager.getConnectedDevices(BluetoothProfile.GATT_SERVER);
for (BluetoothDevice device : gattServerConnectedDevices) {
Log.d("Tag", "Found connected device: " + device.getAddress());
}

Adam Johns
- 35,397
- 25
- 123
- 176
-
3This is only for gatt devices. i need headphone, bluetooth headsets, etc. – user2812299 Jul 27 '17 at 15:09
-
1
Try this method, API 18 though.

pelotasplus
- 9,852
- 1
- 35
- 37
-
1Can you provide an example please. Everything I have tried uses broadcast receivers, but I want to query in onCreate method. – user2812299 Feb 27 '14 at 21:58
-
1FYI, this only works for BluetoothProfile.GATT and BluetoothProfile.GATT_SERVER. – swooby May 17 '16 at 05:00
1
It's possible to list connected headset devices via BluethoothHeadset service
btAdapter.getProfileProxy(context, object : BluetoothProfile.ServiceListener {
override fun onServiceDisconnected(p0: Int) {
//
}
override fun onServiceConnected(p0: Int, headset: BluetoothProfile?) {
headset?.connectedDevices?.forEach {
Timber.d("${it.name} ${it.address}")
}
}
}, BluetoothProfile.HEADSET)

adray
- 1,408
- 16
- 20