Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Android Bluetooth Low Energy (BLE) Resources

Background

Platform-Agnostic

Android-Specific

Libraries

Building

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

In-Depth Guides

  • "Bluetooth Low Energy on Android: Top Tips For The Tricky Bits" by Stuart Kent (slides, video) - My own talk!
  • "Bluetooth Low Energy on Android" series by Erik Hellman (post 1) (post 2) - Comprehensive introductory articles.
  • Android BLE Issues - A fairly complete list of symptoms you are likely to encounter while working with Android's BLE stack. Some apply to pre-Lollipop only, but many still exist and occur.

Implementations

Android Source Code

Stack Overflow

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

Google Issues

@zewenhs

This comment has been minimized.

Copy link

zewenhs commented Dec 19, 2018

good, very good!

@harishankar-jayasakthi

This comment has been minimized.

Copy link

harishankar-jayasakthi commented Sep 24, 2019

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

@stkent

This comment has been minimized.

Copy link
Owner 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

This comment has been minimized.

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:
20191106_153901

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

This comment has been minimized.

Copy link
Owner 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

This comment has been minimized.

Copy link

sarbogast commented Nov 6, 2019

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

This comment has been minimized.

Copy link
Owner Author

stkent commented Nov 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.