Skip to content

Instantly share code, notes, and snippets.

@stkent
Last active August 1, 2024 08:47
Show Gist options
  • Save stkent/a7f0d6b868e805da326b112d60a9f59b to your computer and use it in GitHub Desktop.
Save stkent/a7f0d6b868e805da326b112d60a9f59b to your computer and use it in GitHub Desktop.
Android Bluetooth Low Energy (BLE) Resources

Background

Platform-Agnostic

Android-Specific

  • "Android Lollipop: Bluetooth LE Matures" (video).
  • "Bluetooth (LE) with Dave (devunwired) Smith" (podcast).
  • "State of BLE on Android in 2022" (slides, video).

Libraries

Building

Resources relevant to building Bluetooth Low Energy Android applications from scratch.

In-Depth Guides

Implementations

Android Source Code

Stack Overflow

Useful users, questions, answers, and comments from Stack Overflow's Q&A.

Google Issues

(You must sign in with a Google account to access these.)

@zewenhs
Copy link

zewenhs commented Dec 19, 2018

good, very good!

Copy link

ghost commented Sep 24, 2019

I faced this issue, BLE scan is not working when screen is off on Android 9.0 and above

@stkent
Copy link
Author

stkent commented Oct 15, 2019

@harishankar-jayasakthi do you have location permission granted at all times (not just while app is in use/in the foreground)? Just a guess!

@sarbogast
Copy link

sarbogast commented Nov 6, 2019

When I scan for BLE peripherals without any filter, I see my custom peripheral, but the moment I add a scan filter like the following, I don't see it anymore:

bluetoothAdapter?.bluetoothLeScanner?.startScan(
                arrayListOf(ScanFilter.Builder().setServiceUuid(MY_SERVICE_UUID).build()),
                scanSettingsBuilder.build(),
                leScanCallback
            )

And yet in nrfConnect, I can see the following advertisement data for my BLE peripheral:

Click for image

And of course, the MY_SERVICE_UUID constant matches the service UUID in the screenshot.
Plus, I'm working now on the Android port of an iOS application that scans for BLE devices with the same kind of filters and it works.
How do scan filters work exactly? What is the requirement for a peripheral to be accepted by such a filter?

@stkent
Copy link
Author

stkent commented Nov 6, 2019

Hmm, odd. Does MY_SERVICE_UUID contain the full UUID, not just a custom portion? Do you receive anything in the scan callback, or an error, or just nothing at all?

@sarbogast
Copy link

Here is a more complete version of the code that does not produce any result, nor any error. The callback is just never called.

bluetoothAdapter?.bluetoothLeScanner?.startScan(
    arrayListOf(ScanFilter.Builder().setServiceUuid(ParcelUuid(UUID.fromString("00004865-726f-6e54-7261-636b2d475053"))).build()),
    scanSettingsBuilder.build(),
    leScanCallback
)

@stkent
Copy link
Author

stkent commented Nov 8, 2019

@stkent
Copy link
Author

stkent commented Apr 25, 2020

@ret394 thanks for the note; I added a comment about signing in to the Google issues links.

@comann
Copy link

comann commented Oct 6, 2020

any future considerations for adding documentation for the DeviceCompanion API that targets api 26 or higher?

@stkent
Copy link
Author

stkent commented Oct 6, 2020

@comann unfortunately I haven't worked with Bluetooth for many years, and have no plans to do so in the near future :(. The new APIs you mention look interesting but also appear to operate at a higher level of abstraction than the APIs documented here. I would probably recommend creating a separate document if you are looking to collect resources on them specifically.

@ctkqiang
Copy link

Do you have the Qualcomm CSR BLE ?

@stkent
Copy link
Author

stkent commented Jan 13, 2021

Not sure what you're asking, sorry John! So the answer is probably: no :)

@ctkqiang
Copy link

Not sure what you're asking, sorry John! So the answer is probably: no :)

Ouch , Thanks Anyway :)

@SmrutiRanjanSahoo1997
Copy link

please help me solving GATT_ERROR 133.
I am stock here and can't go ahead.
It shows 7times outof 10.
specifically number of times decreases or increased according to phone models.

Thanks in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment