Smart Camera Pairing in QR Code Mode

Last Updated on : 2023-04-17 09:04:15download

A smart camera can scan a QR code on the app to get the pairing data. Users can pair the smart camera in this way.

Pairing process

Smart Camera Pairing in QR Code Mode

Initialize pairing parameters

API description

ThingCameraActivatorBuilder builder = new ThingCameraActivatorBuilder()
		 .setListener(new IThingSmartCameraActivatorListener() {
			 public void onQRCodeSuccess(String qrcodeUrl) {
				 // The URL used to generate a QR code.

			 public void onError(String errorCode, String errorMsg) {
				 // Failed to pair the device.

			 public void onActiveSuccess(DeviceBean devResp) {
				// The device is paired.


Parameter Description
token The pairing token.
context The context to be set in activity.
ssid The name of the Wi-Fi network to which a paired device is connected.
password The password of the Wi-Fi network to which a paired device is connected.
timeout The timeout value of a pairing task. Default value: 100. Unit: seconds.

Get a token

Before the smart camera pairing process, the SDK must get a pairing token from the cloud in the networked state. The token is valid for 10 minutes and expires immediately after the device is paired. A new token must be generated if the device needs to be paired again.

API description

		new IThingActivatorGetToken() {

			public void onSuccess(String token) {


			public void onFailure(String s, String s1) {



Parameter Description
homeId The home ID. For more information, see Home Management.

Call the pairing method

  • Pairing implementation class.

    IThingCameraDevActivator mThingActivator = ThingHomeSdk.getActivatorInstance().newCameraDevActivator(builder);
  • Returns the URL of the QR code.

    mThingActivator.createQRCode(); // The result is returned by the callback of `onQRCodeSuccess`.
  • Generates a QR code by using the URL.

    In the following example, this dependency is required: zxing (implementation '').

    public static Bitmap createQRCode(String url, int widthAndHeight)
    			throws WriterException {
    		Hashtable hints = new Hashtable();
    		hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
    		BitMatrix matrix = new MultiFormatWriter().encode(url,
    				BarcodeFormat.QR_CODE, widthAndHeight, widthAndHeight, hints);
    		int width = matrix.getWidth();
    		int height = matrix.getHeight();
    		int[] pixels = new int[width * height];
    		for (int y = 0; y < height; y++) {
    			for (int x = 0; x < width; x++) {
    				if (matrix.get(x, y)) {
    					pixels[y * width + x] = BLACK;
    		Bitmap bitmap = Bitmap.createBitmap(width, height,
    		bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    		return bitmap;
  • Starts pairing.

  • Stops pairing.

  • Destroys data.