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 './basic'; 17 18/** 19 * Provides methods to operate or manage NFC. 20 * 21 * @import import controller from '@ohos.nfc.controller'; 22 * 23 * @since 7 24 * @syscap SystemCapability.Communication.NFC.Core 25 */ 26declare namespace nfcController { 27 enum NfcState { 28 /** Indicates that NFC is disabled. */ 29 STATE_OFF = 1, 30 31 /** Indicates that NFC is being enabled. */ 32 STATE_TURNING_ON = 2, 33 34 /** Indicates that NFC is enabled. */ 35 STATE_ON = 3, 36 37 /** Indicates that NFC is being disabled. */ 38 STATE_TURNING_OFF = 4, 39 } 40 41 /** 42 * Checks whether a device supports NFC. 43 * 44 * @return Returns {@code true} if the device supports NFC; returns {@code false} otherwise. 45 * 46 * @since 7 47 */ 48 function isNfcAvailable(): boolean 49 50 /** 51 * register nfc state changed event. 52 * 53 * @param type the type to register. 54 * @param callback Callback used to listen for the nfc state changed event. 55 * 56 * @since 7 57 */ 58 59 function on(type: "nfcStateChange", callback: Callback<NfcState>): void 60 61 /** 62 * unregister nfc state changed event. 63 * 64 * @param type the type to unregister. 65 * @param callback Callback used to listen for the nfc state changed event. 66 * 67 * @since 7 68 */ 69 70 function off(type: "nfcStateChange", callback?: Callback<NfcState>): void 71 72 /** 73 * Enables NFC. 74 * 75 * @return Returns {@code true} if NFC is enabled or has been enabled; returns {@code false} otherwise. 76 * @permission ohos.permission.MANAGE_SECURE_SETTINGS 77 * 78 * @since 7 79 */ 80 function openNfc(): boolean 81 82 /** 83 * Disables NFC. 84 * 85 * @return Returns {@code true} if NFC is disabled or has been disabled; returns {@code false} otherwise. 86 * @permission ohos.permission.MANAGE_SECURE_SETTINGS 87 * 88 * @since 7 89 */ 90 function closeNfc(): boolean 91 92 /** 93 * Checks whether NFC is enabled. 94 * 95 * @return Returns {@code true} if NFC is enabled; returns {@code false} otherwise. 96 * 97 * @since 7 98 */ 99 function isNfcOpen(): boolean 100 101 /** 102 * Obtains the NFC status. 103 * 104 * <p>The NFC status can be any of the following: <ul><li>{@link #STATE_OFF}: Indicates that NFC 105 * is disabled. <li>{@link #STATE_TURNING_ON}: Indicates that NFC is being enabled. 106 * <li>{@link #STATE_ON}: Indicates that NFC is enabled. <li>{@link #STATE_TURNING_OFF}: Indicates 107 * that NFC is being disabled.</ul> 108 * 109 * @return Returns the NFC status. 110 * 111 * @since 7 112 */ 113 function getNfcState(): NfcState 114} 115 116export default nfcController; 117