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?
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());
}
Try this method, API 18 though.
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.