flutter_reactive_ble
flutter_reactive_ble copied to clipboard
App Closes When Trying to Disconnect
Describe the bug I'm trying to disconnect from the device, but an exception is thrown. Never appeared until now.
To Reproduce Steps to reproduce the behavior:
- Connect to one device using
connectTo()
- I disconnected from the device and got the error
Expected behavior
When I tried to disconnect from the device the application crashed and returned this in the console:
Smartphone / tablet
- Device: Samsung M62
- OS: Android 13
- Package version: 5.0.3
@yuriboeira11tx This is the same issue, I am facing. Did you find any solution?
@yuriboeira11tx Same issue here also.No issue with IOS . App Crashes when Device is disconnected Any way to reach the repo maintainer. Need help..
Hi, you need to catch the error in the android manifest. There are similiar issues. Here is how you can solve this problem in Kotlin:
class MainActivity : FlutterActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine);
RxJavaPlugins.setErrorHandler { throwable ->
if (throwable is UndeliverableException) {
println('!'.code * 80)
println("Caught UndeliverableException from flutter_reactive_ble.")
println('!'.code * 80)
return@setErrorHandler // ignore BleExceptions as they were surely delivered at least once
}
throw RuntimeException("Unexpected Throwable in RxJavaPlugins error handler", throwable)
}
}
}
yes duplicated check #768
Hi, you need to catch the error in the android manifest. There are similiar issues. Here is how you can solve this problem in Kotlin:
class MainActivity : FlutterActivity() { override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { super.configureFlutterEngine(flutterEngine); RxJavaPlugins.setErrorHandler { throwable -> if (throwable is UndeliverableException) { println('!'.code * 80) println("Caught UndeliverableException from flutter_reactive_ble.") println('!'.code * 80) return@setErrorHandler // ignore BleExceptions as they were surely delivered at least once } throw RuntimeException("Unexpected Throwable in RxJavaPlugins error handler", throwable) } } }
Full example: Add in build.gradle
...
dependencies {
implementation 'com.google.protobuf:protobuf-javalite:3.17.3'
implementation 'io.reactivex.rxjava2:rxkotlin:2.4.0' //ADD THIS
}
MainActivity.kt in Android/app/src/...
package com.X.Y.U
import io.flutter.embedding.android.FlutterActivity
import androidx.annotation.NonNull
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import io.reactivex.exceptions.UndeliverableException
import io.reactivex.plugins.RxJavaPlugins
class MainActivity : FlutterActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine);
RxJavaPlugins.setErrorHandler { throwable ->
if (throwable is UndeliverableException) {
println('!'.code * 80)
println("Caught UndeliverableException from flutter_reactive_ble.")
println('!'.code * 80)
return@setErrorHandler // ignore BleExceptions as they were surely delivered at least once
}
throw RuntimeException("Unexpected Throwable in RxJavaPlugins error handler", throwable)
}
}
}