Device Interconnection
Device Interconnection
Importing Modules
import interconnect from '@system.interconnect'
API Definitions
instance
Creates a Connect instance.
const connect = interconnect.instance({
package: "com.xxxx.xxx",
fingerprint: "xxxxx"
})
- package: Package name of the mobile app.
- fingerprint: Fingerprint information, which must match the fingerprint information passed when the mobile app creates the connection.
Connect Interface
onopen
Specifies the callback when the connection is opened.
connect.onopen = () => {
console.info("onopen")
}
onclose
Specifies the callback when the connection is closed.
connect.onclose = () => {
console.info("onclose")
}
onerror
Specifies the callback for connection failure.
connect.onerror = (data: any) => {
console.info("onerror", data)
}
onmessage
Specifies the callback for receiving data from the mobile app.
connect.onmessage = (msg => {
if (msg.isFileType) {
this.msg = "recv a file " + msg.fileUri
} else {
this.msg = "recv a text message " + msg.data
}
})
send
Send data to the mobile app
connect.send({
data: {
name: "zhangsan"
}
})
