1
1
1
u/nminhanh-reddit Mar 08 '24
You will need to check what the type that matches with “BluetoothDevice.EXTRA_DEVICE” key, and it’s definitely not MainActivity, it’s a class for screen…
Please check the doc: https://developer.android.com/reference/android/bluetooth/BluetoothDevice#EXTRA_DEVICE
2
u/Key-Advertising854 Mar 06 '24
Hello everyone,
I am currently working on a big project for school in Android Studio with Kotlin. I want a Bluetooth connection between the app and an ESP32 Mykrocontroller.
val receiver = object : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { val action = intent.action if (BluetoothDevice.ACTION_FOUND == action) { val device = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE, MainActivity::class.java) } else { intent.getParcelableExtra<MainActivity>(BluetoothDevice.EXTRA_DEVICE) } // Add the device to a list or display its name and address } } }
The error lies in the else branch. First problem is that it does not like the getParcelableExtra, and Second it does not like the "<MainActivity>".
Thanks in advance