Integrate into HarmonyOS NEXT

Updated at:

Enable the debug path

To enable the debug path, add setEnableDebugPath(true) to config during the card engine initialization.

CubeEngineConfig.obtain()
  .setEnableDebugPath(true)
Important

Disable the debug path for production packages.

Customize a scan page

You can customize a scan page and call the MPCube.scan method from the button.

@Entry
@Component
struct ScanPage {
  @State instance: CubeCard | null = null;

  aboutToAppear() {
  }

  aboutToDisappear() {
    if (this.instance) {
      this.instance.destroy();
    }
  }

  build() {
    Stack() {
      Column() {
          Button("Scan")
            .width('100%')
            .height('60')
            .fontSize(30)
            .onClick(() => {
              MPCube.scan((card,errorMsg)=>{
                if(null!==errorMsg){
                  prompt.showToast({
                    message: errorMsg,
                    duration: 2000
                  });
                  return
                }
                if(null!=card){
                  this.instance = card;
                }
              })
            })
        if (this.instance) {
          CubeCardComponent({ instance: this.instance })
        }
      }
      .justifyContent(FlexAlign.Center)
    }
  }
}
Note
  • If the scan is successful, a non-empty card instance is returned. Pass this instance to CubeCardComponent to render the card.

  • If the scan fails, the returned card is empty and errorMsg is not empty.

Localize the scan feature

  1. You can download Visual Studio.

  2. Click Open Folder and select a folder with a path that contains only English characters.

    image.png

  3. Create an index.html file in the folder. This file can contain any content.

  4. Click Go Live to publish.

    image.png

  5. Copy the generated main.zip and mock.json files to the project folder.

  6. Generate a QR code.

    Use the URL format below for the QR code. Replace the IP address and port number with your local IP address and the port number provided by Go Live.

    cid=aaa@cver=1.0.X.X@url=http://30.172.XX.XXX:8082/main.zip@jsonUrl=http://30.172.82.148:8082/mock.json
  7. How to publish a card project without replacing the files in the publish directory?

    1. In the card project, create a cd.sh file and copy the following code into it.

      #!/bin/bash
      cubePath="/Users/wzh/cubeLib/mp-video"       # Local card path
      cardName="mp-video"           # Card name
      outPath="/Users/wzh/Documents/cube"        # Output path, which is the publish folder
      
      cd $cubePath
      act build
      cp "$cubePath/mock.json" "$outPath/"
      cp "$cubePath/dist/$cardName/main.zip" "$outPath/"
    2. Modify cubePath, cardName, and outPath in the file.

    3. Execute the sh command to automatically build the project.

    4. Copy the built files to the publish folder.

      Note

      Stop the HarmonyOS application process and then scan the QR code again.