可以查询当前NFC状态,以及监听NFC状态变化参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-nfccontroller-0000001813576588\#ZH-CN\_TOPIC\_0000001813576588\_\_nfcstate测试验证controller.isNfcOpen()返回值正确的,demo如下:import controller from '@ohos.nfc.controller' @Entry @Component struct TestNetConnectionPage { @State monitorNfcState: string = ''; @State queryNfcState: string = ''; @State isNfcOpen: boolean = false; aboutToAppear(): void { if (canIUse("SystemCapability.Communication.NFC.Core")) { controller.on("nfcStateChange", state => { this.monitorNfcState = state.toString(); }); } } build() { Row() { Column() { Row() { Text('监听NFC状态:').width('50%'); Text(this.monitorNfcState).width('50%'); }.alignSelf(ItemAlign.Start); if (canIUse("SystemCapability.Communication.NFC.Core")) { Row() { Button('查询NFC状态:').width('50%').onClick(() => { this.queryNfcState = controller.getNfcState().toString(); }); Text(this.queryNfcState).width('50%'); }.alignSelf(ItemAlign.Start); } if (canIUse("SystemCapability.Communication.NFC.Core")) { Row() { Button('查询NFC开关:').width('50%').onClick(() => { this.isNfcOpen = controller.isNfcOpen(); }); Text(this.isNfcOpen + '').width('50%'); }.alignSelf(ItemAlign.Start); } } .width('100%') } .height('100%') } }
可以查询当前NFC状态,以及监听NFC状态变化
参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-nfccontroller-0000001813576588\#ZH-CN\_TOPIC\_0000001813576588\_\_nfcstate
测试验证controller.isNfcOpen()返回值正确的,demo如下: