02.Scan device - htangsmart/FitCloudPro-SDK-Android GitHub Wiki
Bluetooth scanning is a fairly complex affair, and this document lists three scanning APIs you might use. You can choose any one of them to perform the scan job. But before using it, make sure you understand the following scan-related:
- You need to ensure that the device supports
BLEand the Bluetooth is enabled - You have granted the corresponding permissions for Bluetooth scanning. Please refer to here for the specific permissions required.
- Understand the effect of Location Service on scan results: https://issuetracker.google.com/issues/37065090
- Devices paired or connected by the system may not be scanned.
- Scanning may produce various errors, you need to design a friendly prompt to tell the user how to try next.
Use FcScanner
sample project: Refer to
ScannerHelper.kt
FcScanner is a scanning helper class provided by the SDK. For the scanning process, it provides some additional implementations:
-
Filter devices. Only return
FitClouddevicesCurrently, we use companyId to distinguish whether it is a
FitClouddevice. The companyId of FitCloud devices may be one of the following: 0x5448,0x4254,0x5A54 -
Use different scanning modes for different scenes in the foreground and background.
For the foreground, use
ScanSettings.SCAN_MODE_LOW_LATENCY. For the background, useScanSettings.SCAN_MODE_LOW_POWER. -
Optimize the exception of
BleScanException.UNDOCUMENTED_SCAN_THROTTLE.
val scanner = fcSDK.scanner
scanDisposable = scanner.scan(120, TimeUnit.SECONDS, checkLocationServiceFirst = false, acceptEmptyDeviceName = true)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
listener?.onScanResult(it)
}, {
//Analysis error
analysisScanError(it)
})