鸿蒙开发之@ohos.nfc.cardEmulation (标准NFC-cardEmulation)

导入模块

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

FeatureType

定义不同的NFC卡模拟类型。

NOTE
从 API version 6 开始支持,从 API version 9 开始废弃,建议使用hasHceCapability替代。

系统能力: SystemCapability.Communication.NFC.CardEmulation

在这里插入图片描述

CardType9+

定义卡模拟应用所使用的业务类型,是支付类型,还是其他类型。

系统能力: SystemCapability.Communication.NFC.CardEmulation

在这里插入图片描述

isSupported

isSupported(feature: number): boolean

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

NOTE
从 API version 6 开始支持,从 API version 9 开始废弃,建议使用hasHceCapability替代。

系统能力: SystemCapability.Communication.NFC.CardEmulation

参数:

在这里插入图片描述

返回值:

在这里插入图片描述

hasHceCapability9+

hasHceCapability(): boolean

判断是否支持HCE功能。

系统能力: SystemCapability.Communication.NFC.CardEmulation

需要权限: ohos.permission.NFC_CARD_EMULATION

返回值:

在这里插入图片描述

isDefaultService9+

isDefaultService(elementName: ElementName, type: CardType): boolean

判断指定的应用是否为指定业务类型的默认应用。

系统能力: SystemCapability.Communication.NFC.CardEmulation

需要权限: ohos.permission.NFC_CARD_EMULATION

参数:

在这里插入图片描述

返回值:
在这里插入图片描述

示例:

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

var isHceSupported = cardEmulation.isSupported(cardEmulation.FeatureType.HCE);
if (!isHceSupported) {
    console.log('this device is not supported for HCE, ignore it.');
    return;
}

var hasHceCap = cardEmulation.hasHceCapability();
if (!hasHceCap) {
    console.log('this device hasHceCapability false, ignore it.');
    return;
}

var elementName = {
    "bundleName": "com.test.cardemulation",
    "abilityName": "com.test.cardemulation.MainAbility",
};
var isDefaultService = cardEmulation.isDefaultService(elementName, cardEmulation.CardType.PAYMENT);
console.log('is the app is default service for this card type: ' + isDefaultService);
  • 4
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值