저전력 블루투스 기기를 찾으려면
startScan() 드림
메서드를 사용하여 축소하도록 요청합니다. 이 메서드는
ScanCallback을 매개변수로 사용합니다.
이 콜백을 통해 스캔 결과가 반환되므로 반드시 구현해야 합니다.
스캔은 배터리를 많이 사용하므로 다음 사항에 유의해야 합니다.
가이드라인:
원하는 기기를 찾는 즉시 스캔을 중단합니다.
루프에서 스캔하지 말고 항상 스캔에 시간 제한을 설정하세요.
이전에 사용할 수 있었던 항목이 범위를 벗어났을 수 있으며
배터리가 소모됩니다.
다음 예에서 BLE 앱은
(DeviceScanActivity)를 통해 사용 가능한 블루투스 저전력 기기 및 디스플레이 검색
사용자에게 제공할 수 있습니다 다음 스니펫은
스캔:
Kotlin
privatevalbluetoothLeScanner=bluetoothAdapter.bluetoothLeScannerprivatevarscanning=falseprivatevalhandler=Handler()// Stops scanning after 10 seconds.privatevalSCAN_PERIOD:Long=10000privatefunscanLeDevice(){if(!scanning){// Stops scanning after a pre-defined scan period.handler.postDelayed({scanning=falsebluetoothLeScanner.stopScan(leScanCallback)},SCAN_PERIOD)scanning=truebluetoothLeScanner.startScan(leScanCallback)}else{scanning=falsebluetoothLeScanner.stopScan(leScanCallback)}}
자바
privateBluetoothLeScannerbluetoothLeScanner=bluetoothAdapter.getBluetoothLeScanner();privatebooleanscanning;privateHandlerhandler=newHandler();// Stops scanning after 10 seconds.privatestaticfinallongSCAN_PERIOD=10000;privatevoidscanLeDevice(){if(!scanning){// Stops scanning after a predefined scan period.handler.postDelayed(newRunnable(){@Overridepublicvoidrun(){scanning=false;bluetoothLeScanner.stopScan(leScanCallback);}},SCAN_PERIOD);scanning=true;bluetoothLeScanner.startScan(leScanCallback);}else{scanning=false;bluetoothLeScanner.stopScan(leScanCallback);}}
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[null,null,["최종 업데이트: 2025-07-27(UTC)"],[],[],null,["# Find BLE devices\n\nTo find BLE devices, you use the\n[`startScan()`](/reference/android/bluetooth/le/BluetoothLeScanner#startScan(android.bluetooth.le.ScanCallback))\nmethod. This method takes a\n[`ScanCallback`](/reference/android/bluetooth/le/ScanCallback) as a parameter.\nYou must implement this callback, because that is how scan results are returned.\nBecause scanning is battery-intensive, you should observe the following\nguidelines:\n\n- As soon as you find the desired device, stop scanning.\n- Never scan on a loop, and always set a time limit on your scan. A device that was previously available may have moved out of range, and continuing to scan drains the battery.\n\nIn the following example, the BLE app provides an activity\n(`DeviceScanActivity`) to scan for available Bluetooth LE devices and display\nthem in a list to the user. The following snippet shows how to start and stop a\nscan: \n\n### Kotlin\n\n```kotlin\nprivate val bluetoothLeScanner = bluetoothAdapter.bluetoothLeScanner\nprivate var scanning = false\nprivate val handler = Handler()\n\n// Stops scanning after 10 seconds.\nprivate val SCAN_PERIOD: Long = 10000\n\nprivate fun scanLeDevice() {\n if (!scanning) { // Stops scanning after a pre-defined scan period.\n handler.postDelayed({\n scanning = false\n bluetoothLeScanner.stopScan(leScanCallback)\n }, SCAN_PERIOD)\n scanning = true\n bluetoothLeScanner.startScan(leScanCallback)\n } else {\n scanning = false\n bluetoothLeScanner.stopScan(leScanCallback)\n }\n}\n```\n\n### Java\n\n```java\nprivate BluetoothLeScanner bluetoothLeScanner = bluetoothAdapter.getBluetoothLeScanner();\nprivate boolean scanning;\nprivate Handler handler = new Handler();\n\n// Stops scanning after 10 seconds.\nprivate static final long SCAN_PERIOD = 10000;\n\nprivate void scanLeDevice() {\n if (!scanning) {\n // Stops scanning after a predefined scan period.\n handler.postDelayed(new Runnable() {\n @Override\n public void run() {\n scanning = false;\n bluetoothLeScanner.stopScan(leScanCallback);\n }\n }, SCAN_PERIOD);\n\n scanning = true;\n bluetoothLeScanner.startScan(leScanCallback);\n } else {\n scanning = false;\n bluetoothLeScanner.stopScan(leScanCallback);\n }\n}\n```\n| **Note:** The [`BluetoothLeScanner`](/reference/android/bluetooth/le/BluetoothLeScanner) is only available from the [`BluetoothAdapter`](/reference/android/bluetooth/BluetoothAdapter) if Bluetooth is currently enabled on the device. If Bluetooth is not enabled, then [`getBluetoothLeScanner()`](/reference/android/bluetooth/BluetoothAdapter#getBluetoothLeScanner()) returns null.\n\nTo scan for only specific types of peripherals, you can instead call\n[`startScan(List\u003cScanFilter\u003e, ScanSettings, ScanCallback)`](/reference/android/bluetooth/le/BluetoothLeScanner#startScan(java.util.List%3Candroid.bluetooth.le.ScanFilter%3E,%20android.bluetooth.le.ScanSettings,%20android.bluetooth.le.ScanCallback)),\nproviding a list of [`ScanFilter`](/reference/android/bluetooth/le/ScanFilter)\nobjects that restrict the devices that the scan looks for and a\n[`ScanSettings`](/reference/android/bluetooth/le/ScanSettings) object that\nspecifies parameters about the scan.\n\nThe following code sample is an implementation of\n[`ScanCallback`](/reference/android/bluetooth/le/ScanCallback),\nwhich is the interface used to deliver BLE scan results. When results are found,\nthey are added to a list adapter in the `DeviceScanActivity` to display to the\nuser. \n\n### Kotlin\n\n```kotlin\nprivate val leDeviceListAdapter = LeDeviceListAdapter()\n// Device scan callback.\nprivate val leScanCallback: ScanCallback = object : ScanCallback() {\n override fun onScanResult(callbackType: Int, result: ScanResult) {\n super.onScanResult(callbackType, result)\n leDeviceListAdapter.addDevice(result.device)\n leDeviceListAdapter.notifyDataSetChanged()\n }\n}\n```\n\n### Java\n\n```java\nprivate LeDeviceListAdapter leDeviceListAdapter = new LeDeviceListAdapter();\n\n// Device scan callback.\nprivate ScanCallback leScanCallback =\n new ScanCallback() {\n @Override\n public void onScanResult(int callbackType, ScanResult result) {\n super.onScanResult(callbackType, result);\n leDeviceListAdapter.addDevice(result.getDevice());\n leDeviceListAdapter.notifyDataSetChanged();\n }\n };\n```\n| **Note:** You can only scan for Bluetooth LE devices *or* scan for classic Bluetooth devices, as described in [Bluetooth overview](/develop/connectivity/bluetooth). You can't scan for both Bluetooth LE and classic devices at the same time."]]