Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ble Undeliverable Exception Documentation #88

Closed
0p3r4t0r opened this issue Jul 15, 2020 · 3 comments
Closed

Ble Undeliverable Exception Documentation #88

0p3r4t0r opened this issue Jul 15, 2020 · 3 comments
Labels
documentation Improvements or additions to documentation
Milestone

Comments

@0p3r4t0r
Copy link

Is your feature request related to a problem? (please describe)
The ReadMe section for Ble Undeliverable Exception should contain a complete working code sample and some more detailed instructions.

Describe the solution you'd like
To catch the Ble Undeliverable exception in Java you can do the following . . .

  1. Add implementation "com.polidea.rxandroidble2:rxandroidble:1.11.1" to the dependencies section of your build.gradle file (source).

  2. Then add the following to MainActivity.java

import io.flutter.embedding.android.FlutterActivity;
import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import com.polidea.rxandroidble2.exceptions.BleException;
import io.reactivex.exceptions.UndeliverableException;
import io.reactivex.plugins.RxJavaPlugins;

public class MainActivity extends FlutterActivity {
    public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
        super.configureFlutterEngine(flutterEngine);
        RxJavaPlugins.setErrorHandler(throwable -> {
            if (throwable instanceof UndeliverableException && throwable.getCause() instanceof BleException) {
                System.out.println('!' * 80);
                System.out.println("Caught UndeliverableException from flutter_reactive_ble.");
                System.out.println('!' * 80);
                return; // ignore BleExceptions as they were surely delivered at least once
            }
            throw new RuntimeException("Unexpected Throwable in RxJavaPlugins error handler", throwable);
        });
    }
}

Additional context
As for me, my experience with android is limited and so it took me a long time to build a complete working version from the code you had in your README. Also, you can find some helpful examples here in the RxAndroidBle library examples folder.

@remonh87
Copy link
Contributor

@0p3r4t0r thanks for reporting. I indeed see that I forgot to add the need for adding the polidea library in this example. Regarding the rest of the code you are working in java and my example was written in Kotlin. Will make that more clear as well. For the rest the issue is not on the RxAndroid library but more on the RXJava side so adding the RXAndroidBLE examples do not add that much value.

@remonh87 remonh87 added the documentation Improvements or additions to documentation label Jul 15, 2020
@0p3r4t0r
Copy link
Author

How about providing some links to the relevant sections of the RxAndroid library? That way you wouldn't clutter your docs and you could probably save your users some Googling.

Something like . . .

@remonh87 remonh87 added this to the 2.4.0 milestone Jul 24, 2020
@remonh87
Copy link
Contributor

improved the readme and it is now available on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants