rxBleClient.scanBleDevices(...) Always Returns Throwable and Not ScanResult
See original GitHub issueDescribe 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:
- Created a year ago
- Comments:9 (1 by maintainers)
Top GitHub Comments
Great idea, I’ll try this
@ZacharyTech Maybe you can contribute your changes to https://github.com/NRB-Tech/RxAndroidBle? This repository seem to be more active.