Home > Mobile >  getDefaultAdapter() method is not supported when i am using this code
getDefaultAdapter() method is not supported when i am using this code

Time:11-24

When I am using this code getDefaultAdapter couldn't supported and enter image description hereshowing toast also wrong.

CodePudding user response:

You can refer to this answer. You can try something like

BluetoothAdapter.getDefaultAdapter()

CodePudding user response:

getDefaultAdapter() will work, but they are recommending you migrate to use BluetoothManager and getAdapter().

In an Activity:

val bluetoothManager = getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
m_bluetoothAdapter = bluetoothManager.adapter

In a Fragment:

val bluetoothManager = requireContext().getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
m_bluetoothAdapter = bluetoothManager.adapter

There is no toast() function. It apparently was provided by the core-ktx Jetpack library at one time and later removed. Use the standard way of showing Toasts.

  • Related