BLE in Mobile Apps: Scanning, Connecting and Moving Data
Bluetooth Low Energy is the usual link between a phone and a nearby device: fitness trackers, locks, meters and the setup step of many Wi-Fi products. The protocol is well defined, but the mobile operating systems wrap it in their own rules on permissions, background operation and connection management. This article covers the three stages every app goes through, scanning, connecting and moving data, and where each usually goes wrong.
At a glance
- 23 bytes
- The default ATT MTU, leaving 20 bytes of payload per packet until a larger MTU is agreed.
- 517 bytes
- The largest ATT MTU defined. Phones and chips often settle on less.
- 0x2902
- The descriptor a client writes to switch on notifications or indications.
- 31 bytes
- The payload limit of a legacy advertising packet, shared by name, UUIDs and data.
The problem
Scanning and connecting differ by platform. Android requires the BLUETOOTH_SCAN and BLUETOOTH_CONNECT permissions from Android 12, and location permission before that. iOS never reveals the device address and assigns its own identifier, so an app cannot recognise a device by its MAC address.
Data transfer has its own traps. Android GATT accepts one operation at a time per connection, so an app that issues several writes without waiting for each callback sees some rejected or lost.
Design the GATT table and the app together. A service that is awkward on a phone gets worked around badly.
Moving data efficiently
GATT exposes data as characteristics grouped into services. Use reads for values the app asks for occasionally, notifications for values the device pushes, and write without response for bulk transfers where the application checks integrity itself. Indications and write with response are acknowledged, so each costs a round trip.
Throughput depends mostly on MTU, connection interval and packets per connection event, all negotiated between phone and device. iOS negotiates MTU automatically; on Android the app requests it. Measure on the phones your users own, as results vary between models.
What good looks like
Filter scans by service UUID rather than name, and stop scanning once the device is found. Android throttles apps that start scans too often.
Wrap every GATT operation in a queue that waits for its callback, with a timeout, and handle disconnection at any point in the sequence.
Test background behaviour, reconnection after the phone sleeps, and Bluetooth switched off mid-transfer, on both platforms.
| Operation | Direction | Acknowledged | Use for |
|---|---|---|---|
| Read | Device to phone, on request | Yes | Occasional values, configuration |
| Write with response | Phone to device | Yes | Commands and settings |
| Write without response | Phone to device | No | Bulk transfer, streaming |
| Notification | Device to phone, pushed | No | Sensor data, status changes |
| Indication | Device to phone, pushed | Yes | Events that must not be missed |
| bytes | |
|---|---|
| MTU 23 | 20 |
| MTU 185 | 182 |
| MTU 247 | 244 |
| MTU 517 | 512 |
What it changes
Reliable Links
Devices are found and reconnected predictably on iOS and Android.
Throughput
MTU and connection parameters suit what the data actually needs.
No Lost Writes
A serialised operation queue removes a whole class of intermittent bugs.
Smooth Permissions
Users are asked for Bluetooth access with clear reasons at the right moment.
Where to go next
Use standard services defined by the Bluetooth SIG, such as Battery Service or Device Information, where they fit. Custom services need 128-bit UUIDs.
Decide early whether data must flow while the app is in the background. Both platforms restrict this, and the design differs if it is needed.
Problems this prevents
- Devices identified by an address iOS never shows
- Overlapping GATT calls that fail intermittently
- Transfers capped by a 20-byte payload
- Scans that drain the phone battery
Discuss your project
Email support@aavico.com or use Get in Touch when the website finishes loading.