FastBle icon indicating copy to clipboard operation
FastBle copied to clipboard

How to scan for Bluetooth Devices

Open EddieXu123 opened this issue 2 years ago • 0 comments

Hi there! Thank you so much for this awesome library!

I'm pretty new to Android programming and was hoping to build an app that can detect a local bluetooth device. I use LightBlue to see if the device is available, and it is (I have the device name and can access one of the service UUIDs). I was just wondering how I would write a simple template to scan for this device with my app? I currently have followed the template up to the BleManager.getInstance().scan(new BleScanCallback() { ... } code, and can see that I have imported everything correctly. In my onCreate(Bundle savedInstanceState) starting function, I did the BleManager.getInstance().init(getApplication());. However, I then have the following code, which works up until the BleManager.getInstance().scan(new BleScanCallback() {...} stuff (in comments right now):

Screen Shot 2022-04-14 at 11 07 28 PM

I was just wondering, how should I write this app such that the scan works? I'm assuming it's because I have everything in my onCreate method but I'm pretty new with callbacks and such, so I wasn't sure. Is there an example project in Java that demonstrates a simple scan for bluetooth devices? Thank you so much!

EddieXu123 avatar Apr 15 '22 03:04 EddieXu123