可能是由于BluetoothManager的调用顺序不正确导致的。以下是一个示例,可以解决此问题:
// 获取BluetoothManager实例
BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
// 获取BluetoothAdapter实例
BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();
// 获取已连接的设备列表
Set connectedDevices = bluetoothAdapter.getBondedDevices();
// 遍历已连接的设备列表
for (BluetoothDevice device : connectedDevices) {
Log.d(TAG, "已连接设备名称:" + device.getName() + ",地址:" + device.getAddress());
}
在这个示例中,使用了正确的调用顺序:先获取BluetoothManager实例,再获取BluetoothAdapter实例,最后获取已连接的设备列表。对获取已连接的设备列表进行遍历可以找到已连接的设备,解决了BluetoothManager.getConnectedDevices方法找不到任何设备的问题。