HarmonyOS Native SDK
Device Discovery
Bluetooth Discovery

Bluetooth Discovery

GizBluetoothManager provides Bluetooth discovery. Initialize the core and Bluetooth modules and obtain runtime permission through native HarmonyOS APIs first.

Observe discovered devices

subscribeBluetoothDeviceList() returns GizState<Array<GizDevice>>. Subscribe before scanning so initial results are not missed.

import { GizDevice } from '@gizwits/smart-sdk';
import { GizBluetoothManager } from '@gizwits/smart-sdk-bluetooth';
 
let bluetoothDevices: Array<GizDevice> = [];
const unsubscribeBluetooth = GizBluetoothManager
  .subscribeBluetoothDeviceList()
  .subscribe((devices: Array<GizDevice>): void => {
    bluetoothDevices = devices;
  });

Start scanning

GizBluetoothManager.startBleScan();

Repeated calls do not start concurrent scans. Results include only devices whose ProductKey matches the core configuration.

Read scan state

const scanning: boolean = GizBluetoothManager.isScanning();

Stop scanning

GizBluetoothManager.stopBleScan();
unsubscribeBluetooth();

Stop the system scan and unsubscribe when the page disappears or nearby devices are no longer needed.

Read advertisements and low-level sessions

const advertisement = GizBluetoothManager.getAdvertisement(device.id);
const session = GizBluetoothManager.getSession(device.id);

These APIs are intended for advanced diagnostics. Normal applications should use device.bleCapability so SDK state and reconnect behavior remain consistent.

If no device appears, check ProductKey, system Bluetooth, runtime permissions, advertisement state, and physical range.