1/* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { Callback } from './@ohos.base'; 17 18/** 19 * Provides methods to operate or manage NFC. 20 * 21 * @namespace nfcController 22 * @syscap SystemCapability.Communication.NFC.Core 23 * @since 7 24 */ 25declare namespace nfcController { 26 enum NfcState { 27 /** 28 * Indicates that NFC is disabled. 29 * 30 * @syscap SystemCapability.Communication.NFC.Core 31 * @since 7 32 */ 33 STATE_OFF = 1, 34 35 /** 36 * Indicates that NFC is being enabled. 37 * 38 * @syscap SystemCapability.Communication.NFC.Core 39 * @since 7 40 */ 41 STATE_TURNING_ON = 2, 42 43 /** 44 * Indicates that NFC is enabled. 45 * 46 * @syscap SystemCapability.Communication.NFC.Core 47 * @since 7 48 */ 49 STATE_ON = 3, 50 51 /** 52 * Indicates that NFC is being disabled. 53 * 54 * @syscap SystemCapability.Communication.NFC.Core 55 * @since 7 56 */ 57 STATE_TURNING_OFF = 4 58 } 59 60 /** 61 * Checks whether a device supports NFC. 62 * 63 * @returns { boolean } Returns {@code true} if the device supports NFC; returns {@code false} otherwise. 64 * @syscap SystemCapability.Communication.NFC.Core 65 * @since 7 66 * @deprecated since 9 67 * @useinstead global#canIUse("SystemCapability.Communication.NFC.Core") 68 */ 69 function isNfcAvailable(): boolean; 70 71 /** 72 * register nfc state changed event. 73 * 74 * @param { 'nfcStateChange' } type The type to register. 75 * @param { Callback<NfcState> } callback Callback used to listen to the nfc state changed event. 76 * @syscap SystemCapability.Communication.NFC.Core 77 * @since 7 78 */ 79 function on(type: 'nfcStateChange', callback: Callback<NfcState>): void; 80 81 /** 82 * unregister nfc state changed event. 83 * 84 * @param { 'nfcStateChange' } type The type to unregister. 85 * @param { Callback<NfcState> } callback Callback used to listen to the nfc state changed event. 86 * @syscap SystemCapability.Communication.NFC.Core 87 * @since 7 88 */ 89 function off(type: 'nfcStateChange', callback?: Callback<NfcState>): void; 90 91 /** 92 * Enables NFC. 93 * 94 * @permission ohos.permission.MANAGE_SECURE_SETTINGS 95 * @returns { boolean } Returns {@code true} if NFC is enabled or has been enabled; returns {@code false} otherwise. 96 * @syscap SystemCapability.Communication.NFC.Core 97 * @since 7 98 * @deprecated since 9 99 * @useinstead @ohos.nfc.controller.nfcController#enableNfc 100 */ 101 function openNfc(): boolean; 102 103 /** 104 * Enables NFC. 105 * 106 * @permission ohos.permission.MANAGE_SECURE_SETTINGS 107 * @throws { BusinessError } 201 - Permission denied. 108 * @throws { BusinessError } 801 - Capability not supported. 109 * @throws { BusinessError } 3100101 - NFC state is abnormal in service. 110 * @syscap SystemCapability.Communication.NFC.Core 111 * @since 9 112 */ 113 function enableNfc(): void; 114 115 /** 116 * Disables NFC. 117 * 118 * @permission ohos.permission.MANAGE_SECURE_SETTINGS 119 * @returns { boolean } Returns {@code true} if NFC is disabled or has been disabled; returns {@code false} otherwise. 120 * @syscap SystemCapability.Communication.NFC.Core 121 * @since 7 122 * @deprecated since 9 123 * @useinstead @ohos.nfc.controller.nfcController#disableNfc 124 */ 125 function closeNfc(): boolean; 126 127 /** 128 * Disables NFC. 129 * 130 * @permission ohos.permission.MANAGE_SECURE_SETTINGS 131 * @throws { BusinessError } 201 - Permission denied. 132 * @throws { BusinessError } 801 - Capability not supported. 133 * @throws { BusinessError } 3100101 - NFC state is abnormal in service. 134 * @syscap SystemCapability.Communication.NFC.Core 135 * @since 9 136 */ 137 function disableNfc(): void; 138 139 /** 140 * Checks whether NFC is enabled. 141 * 142 * @returns { boolean } Returns {@code true} if NFC is enabled; returns {@code false} otherwise. 143 * @syscap SystemCapability.Communication.NFC.Core 144 * @since 7 145 */ 146 function isNfcOpen(): boolean; 147 148 /** 149 * Obtains the NFC status. 150 * <p>The NFC status can be any of the following: <ul><li>{@link #STATE_OFF}: Indicates that NFC 151 * is disabled. <li>{@link #STATE_TURNING_ON}: Indicates that NFC is being enabled. 152 * <li>{@link #STATE_ON}: Indicates that NFC is enabled. <li>{@link #STATE_TURNING_OFF}: Indicates 153 * that NFC is being disabled.</ul> 154 * 155 * @returns { NfcState } Returns the NFC status. 156 * @syscap SystemCapability.Communication.NFC.Core 157 * @since 7 158 */ 159 function getNfcState(): NfcState; 160} 161 162export default nfcController; 163