当前位置: 首页> 汽车> 行情 > 鸿蒙开发通信与连接:【@ohos.nfc.cardEmulation (标准NFC-cardEmulation)】

鸿蒙开发通信与连接:【@ohos.nfc.cardEmulation (标准NFC-cardEmulation)】

时间:2025/7/10 7:49:42来源:https://blog.csdn.net/2301_76813281/article/details/139833677 浏览次数: 0次

标准NFC-cardEmulation

本模块主要用于操作及管理NFC卡模拟。

icon-note.gif 说明:  本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

导入模块

import cardEmulation from '@ohos.nfc.cardEmulation';

cardEmulation.isSupported

isSupported(feature: number): boolean

是否支持某种类型的卡模拟

系统能力:SystemCapability.Communication.NFC

返回值:

类型说明
booleantrue:支持该类型卡模拟, false:不支持该类型卡模拟。

HceService

管理HCE卡模拟。在调用HceService的接口前,需要先通过new cardEmulation.HceService()创建实例。

startHCE

startHCE(aidList: string[]): boolean

开始使用HCE能力。

需要权限:ohos.permission.NFC_CARD_EMULATION

系统能力:SystemCapability.Communication.NFC

参数:

参数名类型必填说明
aidListstring[]注册进行卡模拟的aid列表

stopHCE

stopHCE(): boolean

停止使用HCE能力。

需要权限:ohos.permission.NFC_CARD_EMULATION

系统能力:  SystemCapability.Communication.NFC

on

on(type: “hceCmd”, callback: AsyncCallback<number[]>): void;

在startHCE后,订阅对端设备消息。

需要权限:ohos.permission.NFC_CARD_EMULATION

系统能力:SystemCapability.Communication.NFC

参数:

参数名类型必填说明
hceCmdstring订阅的事件类型
callbackAsyncCallback<number[]>订阅的事件回调,入参是符合APDU协议的数据数组

sendResponse

sendResponse(responseApdu: number[]): void;

发送数据到对端设备。

需要权限:ohos.permission.NFC_CARD_EMULATION

系统能力:SystemCapability.Communication.NFC

参数:

参数名类型必填说明
responseApdunumber[]准备发送到对端的数据,入参是符合APDU协议的数据数组

示例:

var hceService = new cardEmulation.HceService();
hceService.startHCE(["F0010203040506", "A0000000041010"
])
hceService.stopHCE();
hceService.on("hceCmd", (err, res) => {if(err.data === 0) {console.log('callback => Operation hceCmd succeeded. Data: ' + JSON.stringify(res));hceService.sendResponse([0x00,0xa4,0x04,0x00,0x0e,0x32,0x50,0x41,0x59,0x2e,0x53,0x59,0x53,0x2e,0x44,0x44,0x46,0x30,0x31,0x00]);} else {console.log('callback => Operation hceCmd failed. Cause: ' + err.data);}
})
关键字:鸿蒙开发通信与连接:【@ohos.nfc.cardEmulation (标准NFC-cardEmulation)】

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: