android getDefaultAdapter(): BluetoothAdapter is deprecated Deprecated in Java

旧写法

android中调用BluetoothAdapter.getDefaultAdapter()提示过时了

BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

```kotlin
val bluetoothAdapter = BluetoothAdapter.getDefaultAdapter()

getDefaultAdapter(): BluetoothAdapter!’ is deprecated. Deprecated in Java

替代的写法

//java
BluetoothAdapter bluetoothAdapter = getSystemService(Context.BLUETOOTH_SERVICE).getAdapter();

// kotlin
val bluetoothAdapter = (getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager).adapter

作者:帅得不敢出门

你可能感兴趣的:(Android平台,java,android,apache)