Scan QR Code on Device

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

This pairing mode only applies to devices that have been connected to the internet.

Initialize IActivator

Parameters

Parameter Type Required Description
mode ActivatorMode Yes The pairing mode.

Example

QRScanActivator qrScanActivator = (QRScanActivator) ActivatorService.activator(ActivatorMode.QRScan);

Example of scanning QR code to get code

Example: depends on implementation 'com.journeyapps:zxing-android-embedded:3.6.0'

Start scanning

Example

IntentIntegrator integrator = new IntentIntegrator(activity);
integrator.initiateScan();

Get scanning result

Example

 @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
        if (result != null && result.getContents() != null) {
            String code = result.getContents();
        }
    }

Initialize pairing parameters

Parameters

Parameter Type Required Description
assetId String Yes The ID of the specified asset or space.
code String Yes The code extracted from the QR code.
QRScanActivatorParams qrScanActivatorParams = new QRScanActivatorParams.Builder()
                .setAssetId("assetId")
                .setCode("code")
                .build();

qrScanActivator.setParams(qrScanActivatorParams);

Register IActivatorListener to listen for pairing result

Parameters

Parameter Type Required Description
listener IActivatorListener Yes The device information returned by the callback.

Example

qrScanActivator.setListener(new IActivatorListener() {
            @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

qrScanActivator.start();

Stop pairing

This method stops device pairing.

Example

qrScanActivator.stop();