Last Updated on : 2024-05-17 03:04:02download
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.
API description
ThingCameraActivatorBuilder builder = new ThingCameraActivatorBuilder()
		 .setContext(context)
		 .setSsid(ssid)
		 .setPassword(password)
		 .setToken(token)
		 .setTimeOut(timeout)
		 .setListener(new IThingSmartCameraActivatorListener() {
			 @Override
			 public void onQRCodeSuccess(String qrcodeUrl) {
				 // The URL used to generate a QR code.
			 }
			 @Override
			 public void onError(String errorCode, String errorMsg) {
				 // Failed to pair the device.
			 }
			 @Override
			 public void onActiveSuccess(DeviceBean devResp) {
				// The device is paired.
			 }
		 }));
Parameters
| 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. | 
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
ThingHomeSdk.getActivatorInstance().getActivatorToken(homeId,
		new IThingActivatorGetToken() {
			@Override
			public void onSuccess(String token) {
			}
			@Override
			public void onFailure(String s, String s1) {
			}
		});
Parameters
| Parameter | Description | 
|---|---|
| homeId | The home ID. For more information, see Home Management. | 
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 'com.google.zxing:core:3.2.1').
public static Bitmap createQRCode(String url, int widthAndHeight)
			throws WriterException {
		Hashtable hints = new Hashtable();
		hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
		hints.put(EncodeHintType.MARGIN,0);
		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.Config.ARGB_8888);
		bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
		return bitmap;
	}
Starts pairing.
mThingActivator.start();
Stops pairing.
mThingActivator.stop();
Destroys data.
mThingActivator.onDestory();
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback