我有一个应用程序,它将通过蓝牙接收语音输入(如果可用),如果不可用,则通过手机麦克风读取。我似乎找不到一种方法来检查是否已连接任何蓝牙设备(不仅仅是配对)。有什么建议吗?
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());
}
通过BluethoothHeadset服务,可以列出已连接的耳机设备。
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)