使用 BLE 時,Android 裝置可做為周邊裝置、中央裝置或兩者。裝置處於周邊模式時,可以傳送廣告封包。裝置可以透過中央模式掃描廣告。Android 裝置可同時做為周邊裝置和中央裝置,在周邊裝置模式下傳送廣告時,與其他 BLE 周邊裝置通訊。支援藍牙 4.1 以下版本的裝置只能在中央模式下使用 BLE。舊型裝置晶片組可能不支援 BLE 周邊裝置模式。
BLE 掃描
使用 BLE 時,Android 裝置可以更有效率地鎖定及掃描特定藍牙裝置。應用程式開發人員可透過 BLE API 建立篩選器,尋找裝置時不必過度依賴主機控制器。
掃描位置
裝置的定位服務可使用藍牙偵測藍牙信標,並提供更精確的位置資訊。使用者啟用這項功能的方式如下:
依序前往「設定」>「安全性與位置資訊」>「位置資訊」。
確認「開啟」/「關閉」
切換按鈕已設為「開啟」。
前往「模式」。
選取「高精確度」或「節約耗電量」模式。
在 Android 11 以下版本中,即使應用程式掃描藍牙只是為了尋找要連線的裝置,仍須取得位置資訊存取權才能使用 BLE 掃描功能。如果使用者停用位置資訊掃描功能,或未授予應用程式位置資訊存取權,應用程式就不會收到任何 BLE 掃描結果。
使用者可以依序前往「設定」>「安全性與位置資訊」>「位置資訊」>「掃描」,然後點選「藍牙掃描」切換鈕,將其設為關閉,即可停用系統層級的藍牙背景掃描功能。這不會影響位置資訊或本機裝置的 BLE 掃描。
篩選掃描結果
Android 6.0 以上版本會在藍牙控制器上進行 BLE 掃描和篩選器比對。裝置可以篩選掃描結果,並向應用程式處理器 (AP) 回報與 BLE 裝置相關的「找到」和「遺失」事件。篩選功能也適用於批次掃描,有助於節省電力,因為裝置會將 BLE 掃描作業卸載至韌體。批次掃描可減少 AP 因 BLE 掃描裝置或信標而喚醒的頻率。
OnFound/OnLost 功能是在藍牙控制器中實作,然後經過測試,確認掃描時不會遺漏 BLE 裝置。這項功能可節省電力,還能帶來下列好處:
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-22 (世界標準時間)。"],[],[],null,["Bluetooth Low Energy (BLE), available in Android 4.3 and higher, creates\nshort connections between devices to transfer bursts of data. BLE remains\nin sleep mode when not connected. This lets BLE provide lower bandwidth and\nreduced power consumption compared to Classic Bluetooth. BLE is ideal for\napps such as a heart-rate monitor or a wireless keyboard. To use BLE,\ndevices need to have a chipset that supports BLE.\n\nImplementation\n\nAll current BLE app profiles are based on the\n[Generic Attribute (GATT) Profile](https://www.bluetooth.com/specifications/gatt).\nWhen an Android-powered device interacts with a BLE device, the device that\nsends information is the server and the device that receives information is\nthe client. Android includes\n[developer APIs for BLE](https://developer.android.com/guide/topics/connectivity/bluetooth-le),\nincluding APIs for interactions between GATT servers and GATT clients. To\ntake full advantage of the BLE APIs, implement the\n[Android Bluetooth HCI Requirements](/docs/core/connect/bluetooth/hci_requirements).\n\nDevice modes\n\nWhen using BLE, an Android-powered device can act as a peripheral device, a\ncentral device, or both. Peripheral mode lets devices send advertisement\npackets. Central mode lets devices scan for advertisements. An Android\ndevice acting as both a peripheral and central device can communicate with\nother BLE peripheral devices while sending advertisements in peripheral\nmode. Devices supporting Bluetooth 4.1 and lower can use BLE only in\ncentral mode. Older device chipsets might not support BLE peripheral mode.\n\nBLE scanning\n\nAn Android-powered device can target and scan for specific Bluetooth devices\nmore efficiently when using BLE. BLE APIs let app developers create filters\nfor finding devices with less involvement from the host controller.\n| **Caution:** BLE scanning typically needs location permissions because BLE scanning identifies objects that can be used for geolocation. Turning off location services turns off Bluetooth scanning. n Android 12 and higher, apps that declare `neverForLocation` can get Bluetooth scanning results even when location services are off. For more details, see [Tristate location permissions](/docs/core/permissions/tristate-perms).\n\nLocation scanning\n\nA device's location services can use Bluetooth to detect Bluetooth beacons\nand provide a more accurate location. This is how users enable the feature:\n\n1. Go to **Settings** \\\u003e **Security \\& Location** \\\u003e **Location**.\n2. Check that the Location **On** /**Off** toggle is in the **On** position.\n3. Go to **Mode**.\n4. Select either **High accuracy** or **Battery saving** mode.\n\nIn Android 11 and lower, individual apps require location permissions to use\nBLE scanning, even if they're scanning only to find devices to connect to.\nIf the user disables location scanning, or doesn't grant an app location\npermissions, then the app won't receive any BLE scanning results.\n\nIn Android 12 and higher, the\n[`BLUETOOTH_SCAN`](https://developer.android.com/reference/android/Manifest.permission#BLUETOOTH_SCAN),\n[`BLUETOOTH_ADVERTISE`](https://developer.android.com/reference/android/Manifest.permission#BLUETOOTH_ADVERTISE),\nand\n[`BLUETOOTH_CONNECT`](https://developer.android.com/reference/android/Manifest.permission#BLUETOOTH_CONNECT)\npermissions can allow apps to scan for nearby devices without needing to\nrequest the location permission. For more information, see\n[Bluetooth permissions](https://developer.android.com/about/versions/12/features/bluetooth-permissions).\n\nUsers can disable system-level Bluetooth background scanning by going to\n**Settings** \\\u003e **Security \\& Location** \\\u003e **Location** \\\u003e **Scanning** and\nclicking the **Bluetooth scanning** toggle to the off position. This\ndoesn't affect BLE scanning for location or local devices.\n\nFilter scan results\n\nAndroid 6.0 and higher includes BLE scanning and filter-matching on the\nBluetooth controller. A device can filter scan results and report\n**found** and **lost** events related to BLE devices to the application\nprocessor (AP). Filtering also works for batch scans, which helps save\npower as the device offloads BLE scanning to the firmware. Batch scans\nreduce how often the AP wakes up due to BLE scanning for devices or\nbeacons.\n\nThe `OnFound`/`OnLost` feature is implemented in the Bluetooth controller\nand then tested to confirm that BLE devices aren't missed in scans. This\nprovides power savings, and it can also provide the following benefits:\n\n- For an `OnFound` event, the main AP wakes up upon the discovery of a specific device.\n- For an `OnLost` event, the AP wakes up when a specific device can't be found.\n- Framework apps get fewer unwanted notifications when a nearby device is in range.\n- Continuous scans enable framework apps to be notified when a device is out of range.\n\nA scan filter can be based on the discovery of a device's advertisements\n(the `OnFound` event). The Java layer can specify parameters such as first\ndiscovery (or a specified number of advertisements since first discovery).\nImplement BLE filtering using the\n[Advertising Packet Content Filter HCI command](/docs/core/connect/bluetooth/hci_requirements#advertising-packet-content-filter)."]]