flutter_reactive_ble icon indicating copy to clipboard operation
flutter_reactive_ble copied to clipboard

App Closes When Trying to Disconnect

Open yuriboeira11tx opened this issue 1 year ago • 4 comments

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:

  1. Connect to one device using connectTo()
  2. 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: image

Smartphone / tablet

  • Device: Samsung M62
  • OS: Android 13
  • Package version: 5.0.3

yuriboeira11tx avatar Apr 28 '23 13:04 yuriboeira11tx

@yuriboeira11tx This is the same issue, I am facing. Did you find any solution?

Ali-Ahmad-dev avatar May 05 '23 12:05 Ali-Ahmad-dev

@yuriboeira11tx Same issue here also.No issue with IOS . App Crashes when Device is disconnected Any way to reach the repo maintainer. Need help..

Hari2653 avatar May 12 '23 10:05 Hari2653

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)
        }
    }
}

MaxWebfactor avatar Jul 19 '23 07:07 MaxWebfactor

yes duplicated check #768

wcoder avatar Jul 22 '23 15:07 wcoder

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)
        }
    }
}

Mir1001 avatar May 12 '24 15:05 Mir1001