I use Arduino Bluetooth Plugin from Unity asset store and build Android app with Unity 2021.3.1. I connect app with BLE device. Quite often when I use scan method and click my device on the list (it should try pairing then) my application crash and I receive an error below. If error doesn't occur I can connect to the device and everything work fine. I don't know why this error doesn't occur every times and by what it depends, but it looks that problem is only with BLE device - I did not observe this when choise other Bluetooth devices (phone or monitor)
The android.bluetooth.BluetoothDevice class is in plugin in .dll file - I am not sure if I can and should edit it.
I searched in other problems with java.lang.ClassCastException, tried edit AndroidManifest but nothing changed. Please help.
--------- beginning of crash
2022-09-21 10:22:15.321 28057-28057/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.DefaultCompany.AppName, PID: 28057
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=6862, result=-1, data=Intent { (has extras) }} to activity {com.DefaultCompany.AppName/com.tony.bluetoothunityapi.EmptyActivity}: java.lang.ClassCastException: android.bluetooth.le.ScanResult cannot be cast to android.bluetooth.BluetoothDevice
at android.app.ActivityThread.deliverResults(ActivityThread.java:5864)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:5903)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:54)
at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2438)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
Caused by: java.lang.ClassCastException: android.bluetooth.le.ScanResult cannot be cast to android.bluetooth.BluetoothDevice
at com.tony.bluetoothunityapi.EmptyActivity.onActivityResult(EmptyActivity.java:90)
at android.app.Activity.dispatchActivityResult(Activity.java:8659)
at android.app.ActivityThread.deliverResults(ActivityThread.java:5857)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:5903)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:54)
at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2438)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)