Scan QR Code on App

Last Updated on : 2024-05-27 06:34:29download

This topic describes how to enable a device with a camera to scan the QR code on the mobile app for pairing.

Initialize IActivator

Parameters

Parameter Type Required Description
mode ActivatorMode Yes The pairing mode.

Example

QRActivator qrActivator = (QRActivator) ActivatorService.activator(ActivatorMode.QR);

Get a pairing token

Parameters

Parameter Type Required Description
assetId String Yes The ID of the specified asset.
callback IndustryDataCallBack Yes The callback.

Example

// Get the asset activation token.
ActivatorService.activatorToken("assetId", new IndustryDataCallBack<String>() {
            @Override
            public void onSuccess(String s) {
                Log.d(TAG, "onSuccess: " + s);
            }

            @Override
            public void onFailure(@NonNull String s, @NonNull String s1) {
                Log.d(TAG, "onFailure: " + s);
            }
        });

Initialize pairing parameters

Parameters

Parameter Type Description
ssid String The SSID of the Wi-Fi network.
password String The password of the Wi-Fi network.
token String The token obtained.

Example

QRActivatorParams qrActivatorParams = new QRActivatorParams.Builder()
                .setToken("token")
                .setWifi("ssid","password")
                .setTimeout(time)
                .build();
qrActivator.setParams(qrActivatorParams);

Register IActivatorListener to listen for pairing result

Parameters

Parameter Type Required Description
listener IQRActivatorListener Yes The callback.

Example

qrActivator.setListener(new IQRActivatorListener() {
            @Override
            public void onQRCodeSuccess(@NonNull String s) {
                // You generate a QR code based on the return result.
                Log.d(TAG, "onQRCodeSuccess: ");

            }

            @Override
            public void onSuccess(@Nullable IDevice iDevice) {
                Log.d(TAG, "onSuccess: ");

            }

            @Override
            public void onError(@NonNull String s, @NonNull String s1) {
                Log.d(TAG, "onError: ");

            }
        });

Start pairing

This method starts device pairing.

Example

qrActivator.start();

Stop pairing

This method stops device pairing.

Example

qrActivator.stop();