Integrate into HarmonyOS NEXT
Enable the debug path
To enable the debug path, add setEnableDebugPath(true) to config during the card engine initialization.
CubeEngineConfig.obtain()
.setEnableDebugPath(true)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)
}
}
}If the scan is successful, a non-empty
cardinstance is returned. Pass this instance toCubeCardComponentto render the card.If the scan fails, the returned
cardis empty anderrorMsgis not empty.
Localize the scan feature
You can download Visual Studio.
Click Open Folder and select a folder with a path that contains only English characters.

Create an
index.htmlfile in the folder. This file can contain any content.Click Go Live to publish.

Copy the generated
main.zipandmock.jsonfiles to the project folder.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.jsonHow to publish a card project without replacing the files in the publish directory?
In the card project, create a
cd.shfile 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/"Modify cubePath, cardName, and outPath in the file.
Execute the sh command to automatically build the project.
Copy the built files to the publish folder.
NoteStop the HarmonyOS application process and then scan the QR code again.