Use of deprecated methods
Hi, I have had a problem with mBtAdapter = BluetoothAdapter.getDefaultAdapter() in trying to implement Bluetooth in Kotlin. So I worked through all the https://developer.android.com/guide/topics/connectivity/bluetooth stuff to use the replacement Bluetooth Manager with bluetoothAdapter: BluetoothAdapter? = bluetoothManager.getAdapter() which seems to work OK. But when I load the recommended example code from BluetoothChat to see if I have got things right this still seems to be using the deprecated method with mBtAdapter = BluetoothAdapter.getDefaultAdapter(). So when I convert this from Java to Kotlin I am back with the original error from using the deprecated getDefaultAdaptor(). Is there an updated example similar to BluetoothChat but in Kotlin that I can look at?
Hi, I have had a problem with mBtAdapter = BluetoothAdapter.getDefaultAdapter() in trying to implement Bluetooth in Kotlin. So I worked through all the https://developer.android.com/guide/topics/connectivity/bluetooth stuff to use the replacement Bluetooth Manager with bluetoothAdapter: BluetoothAdapter? = bluetoothManager.getAdapter() which seems to work OK. But when I load the recommended example code from BluetoothChat to see if I have got things right this still seems to be using the deprecated method with mBtAdapter = BluetoothAdapter.getDefaultAdapter(). So when I convert this from Java to Kotlin I am back with the original error from using the deprecated getDefaultAdaptor(). Is there an updated example similar to BluetoothChat but in Kotlin that I can look at?
You should be able to change the deprecated method:
"mBtAdapter = BluetoothAdapter.getDefaultAdapter()"
to
"mBtAdapter = context.getSystemService(BluetoothManager.class).getAdapter()
I'm a new contributor here so I could be wrong.