这是因为在Android 6.0及以上版本中,使用bluetooth.getDefaultAdapter()会引发警告,建议使用BluetoothManager来获取蓝牙适配器。
以下是示例代码:
// 获取BluetoothManager
BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
// 获取BluetoothAdapter
BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();
使用这种方法获取BluetoothAdapter不会引发警告。