connectivity-samples icon indicating copy to clipboard operation
connectivity-samples copied to clipboard

Use of deprecated methods

Open HjCHgC opened this issue 3 years ago • 1 comments

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?

HjCHgC avatar Jun 22 '22 18:06 HjCHgC

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.

ghost avatar Aug 18 '23 06:08 ghost