Closed chris-otani closed 3 years ago
Do not forget to add
implementation "com.polidea.rxandroidble2:rxandroidble:1.11.1"
to your gradle dependencies and fix the imports
@remonh87 , thanks for the quick response.
I added that to my gradle dependicies. I also added rxkotlin since it couldn't find that package.
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "com.polidea.rxandroidble2:rxandroidble:1.11.1"
implementation 'io.reactivex.rxjava2:rxkotlin:2.4.0'
}
When fixing the imports it looks like It's not properly importing the "RxJavaPlugins". the import is greyed out like its not being used
MainActivity.kt
import io.flutter.embedding.android.FlutterActivity
import com.polidea.rxandroidble2.exceptions.BleException
import io.reactivex.exceptions.UndeliverableException
import io.reactivex.plugins.RxJavaPlugins
class MainActivity: FlutterActivity() {
RxJavaPlugins.setErrorHandler { throwable ->
if (throwable is UndeliverableException && throwable.cause is BleException) {
return@setErrorHandler // ignore BleExceptions since we do not have subscriber
}
else {
throw throwable
}
}
}
Here are the static errors:
Just change your code like this in your MainActivity
import android.os.Bundle
import com.polidea.rxandroidble2.exceptions.BleException
import io.flutter.embedding.android.FlutterActivity
import io.reactivex.exceptions.UndeliverableException
import io.reactivex.plugins.RxJavaPlugins
class MainActivity : FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
RxJavaPlugins.setErrorHandler { throwable ->
if (throwable is UndeliverableException && throwable.cause is BleException) {
return@setErrorHandler // ignore BleExceptions since we do not have subscriber
} else {
throw throwable
}
}
}
}
@keval-devani That did the trick. Thank you!
I'm struggling to add the workaround for the BLE undeliverable exception to my flutter project. I have no Java/Kotlin experience and searched but can't figure out how to properly add it.
I've added the code to my MainActivity.kt but am getting errors. Could you provide more detail on where to add this code?
When I try to run it I get:
CODE:
Any help would be greatly appreciated.