question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

rxBleClient.scanBleDevices(...) Always Returns Throwable and Not ScanResult

See original GitHub issue

Describe the bug I am writing an Android App to try and discover nearby bluetooth devices. I copied the instructions in the Readme up until the “Device Discovery” portion and everything seems to be working (this.startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); makes the app ask the user to turn on Bluetooth). However, I am copying the next portion and it continues to go into the throwable part.

To Reproduce This is my code (simplified without the UI stuff). I just call everything in my onCreate (though putting it in a helper function and then calling that helper in onCreate doesn’t seem to help either 😕). The Log.d that is printed is “NO DEVICES”. (Not sure if this keyword can replace context, I’m pretty new to Android development:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        RxBleClient rxBleClient = RxBleClient.create(this);

        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        int REQUEST_ENABLE_BT = 1;
        this.startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);

        Disposable scanSubscription = rxBleClient.scanBleDevices(
                new ScanSettings.Builder()
                         // .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY) // change if needed
                        // .setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES) // change if needed
                        .build()
                // add filters if needed
        )
                .subscribe(
                        scanResult -> {
                            // Process scan result here.
                            Log.d("Result", "HAS SCAN RESULT");
                        },
                        throwable -> {
                            Log.d("Result", "NO DEVICES");
                            // Handle an error here.
                        }
                );

// When done, just dispose.
        scanSubscription.dispose();

Expected behavior For now, I’m just hoping to be able to access the particular bluetooth low energy device in the code. Some advice on how to best grab that would also be greatly appreciated!

Smartphone (please complete the following information):

  • Device: Google Pixel 5
  • OS: Android 12
  • Library version: 1.13.1

Additional context For now this app can be simplified to putting the Readme code in my onCreate() function at the beginning. Also, I’m not sure if the “context” I am using is correct - I’m pretty new to Android development so if this isn’t correct, I’d appreciate the info! Thank you so much for your help!

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ZacharyTechcommented, Apr 27, 2022

@ZacharyTech Maybe you can contribute your changes to https://github.com/NRB-Tech/RxAndroidBle? This repository seem to be more active.

Great idea, I’ll try this

1reaction
tolot27commented, Apr 26, 2022

@ZacharyTech Maybe you can contribute your changes to https://github.com/NRB-Tech/RxAndroidBle? This repository seem to be more active.

Read more comments on GitHub >

github_iconTop Results From Across the Web

RxAndroidBle - RxBleDevice getName() always returns null
BluetoothDevice may have a null name if it is not broadcasted. You may alternatively check for a name from scanResult.getScanRecord().
Read more >
Leak resulting from RxBleClient.scanBleDevices() #288 - GitHub
I've been pulling my hair out trying to debug a leak in my app when using RxBleClient.scanBleDevices(). My subscribe onNext lambda holds a ......
Read more >
Unit Testing Android BLE Code with RxAndroidBle
Learn how to use RxAndroidBle for unit testing, some code examples, and a case study on unit testing a common BLE business logic....
Read more >
com.polidea.rxandroidble.RxBleClient.scanBleDevices java ...
Best Java code snippets using com.polidea.rxandroidble.RxBleClient.scanBleDevices (Showing top 9 results out of 315) ; scan_for_device() { · scanBleDevices( new ...
Read more >
com.polidea.rxandroidble2.RxBleDevice Example
onWriteFailure(throwable)); if (this.written_success) return true; return false; } } ... private final RxBleClient rxBleClient = RxBleProvider.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found