Pair with QR Code

Last Updated on : 2024-05-14 02:39:13download

The app scans the device’s QR code to pair with it. This is a quick way to pair a single device. It applies to directly connected devices and Bluetooth devices.

Parse the QR code

ThingActivatorCoreKit.getCommonBizOpt().parseQrCode("qrcodeurl", new Business.ResultListener<ScanActionBean>() {
                @Override
                public void onFailure(BusinessResponse bizResponse, ScanActionBean bizResult, String apiName) {

                }

                @Override
                public void onSuccess(BusinessResponse bizResponse, ScanActionBean bizResult, String apiName) {

                }
            });

Parameter description

Parameters Description
qrcodeurl The string of the QR code.

Description of ScanActionBean

Parameters Description
actionName The scan type.
  • The actionName for a directly connected device is "device_net_conn_multi_ver".
  • The actionName for a Bluetooth device is "device_net_conn_bind_blue".
actionData Device Information

Pair a directly-connected device

val builder = ThingDeviceActiveBuilder()
            .setActiveModel(ThingDeviceActiveModeEnum.QR)
            .setContext(context)
            .setUuid(uuid)
            .setRelationId(homeId)
        .setTimeOut(timeout)
            .setListener(object : IThingDeviceStatePauseActiveListener {
                override fun onFind(devId: String) {
                }

                override fun onBind(devId: String) {
                }

                override fun onActiveSuccess(deviceBean: DeviceBean) {

                }

                override fun onActiveError(errorBean: ThingDeviceActiveErrorBean) {

                }

                override fun onActiveLimited(limitBean: ThingDeviceActiveLimitBean) {
                }

        override fun onActivatorStatePauseCallback(stateData: PauseStateData?) {

                }
            })

val activeManager = ThingActivatorCoreKit.getActiveManager().newThingActiveManager()

activeManager.startActive(builder)

Parameter description

Parameters Description
context The context.
uuid The unique identifier of the device.
relationId The ID of the home with which the device is bound.
timeout The timeout value, in seconds.
activeModel The pairing capability enum.
listener The callback for the result of pairing.

Pair a Bluetooth device

val builder = ThingDeviceActiveBuilder()
            .setActiveModel(ThingDeviceActiveModeEnum.BT_QRCODE)
            .setUuid(uuid)
            .setMac(mac)
            .setRelationId(homeId)
        .setTimeOut(timeout)
            .setListener(object : IThingDeviceStatePauseActiveListener {
                override fun onFind(devId: String) {
                }

                override fun onBind(devId: String) {
                }

                override fun onActiveSuccess(deviceBean: DeviceBean) {

                }

                override fun onActiveError(errorBean: ThingDeviceActiveErrorBean) {

                }

                override fun onActiveLimited(limitBean: ThingDeviceActiveLimitBean) {
                }

        override fun onActivatorStatePauseCallback(stateData: PauseStateData?) {

                }
            })

val activeManager = ThingActivatorCoreKit.getActiveManager().newThingActiveManager()

activeManager.startActive(builder)

Parameter description

Parameters Description
mac The MAC address of the device.
uuid The unique identifier of the device.
relationId The ID of the home with which the device is bound.
timeout The timeout value, in seconds.
activeModel The pairing capability enum.
listener The callback for the result of pairing.

Stop pairing

activeManager.stopActive()