• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 * @since 7
22 * @syscap SystemCapability.Communication.NFC.Core
23 */
24declare namespace nfcController {
25  enum NfcState {
26    /** Indicates that NFC is disabled. */
27    STATE_OFF = 1,
28
29    /** Indicates that NFC is being enabled. */
30    STATE_TURNING_ON = 2,
31
32    /** Indicates that NFC is enabled. */
33    STATE_ON = 3,
34
35    /** Indicates that NFC is being disabled. */
36    STATE_TURNING_OFF = 4,
37  }
38
39  /**
40   * Checks whether a device supports NFC.
41   *
42   * @returns Returns {@code true} if the device supports NFC; returns {@code false} otherwise.
43   * @since 7
44   * @deprecated since 9
45   * @useinstead global#canIUse("SystemCapability.Communication.NFC.Core")
46   */
47  function isNfcAvailable(): boolean
48
49  /**
50   * register nfc state changed event.
51   *
52   * @param type the type to register.
53   * @param callback Callback used to listen to the nfc state changed event.
54   * @since 7
55   */
56  function on(type: "nfcStateChange", callback: Callback<NfcState>): void
57
58  /**
59   * unregister nfc state changed event.
60   *
61   * @param type the type to unregister.
62   * @param callback Callback used to listen to the nfc state changed event.
63   * @since 7
64   */
65  function off(type: "nfcStateChange", callback?: Callback<NfcState>): void
66
67  /**
68   * Enables NFC.
69   *
70   * @returns Returns {@code true} if NFC is enabled or has been enabled; returns {@code false} otherwise.
71   * @permission ohos.permission.MANAGE_SECURE_SETTINGS
72   * @since 7
73   * @deprecated since 9
74   * @useinstead @ohos.nfc.controller.nfcController#enableNfc
75   */
76  function openNfc(): boolean
77
78  /**
79   * Enables NFC.
80   *
81   * @throws { BusinessError } 201 - Permission denied.
82   * @throws { BusinessError } 801 - Capability not supported.
83   * @throws { BusinessError } 3100101 - NFC state is abnormal in service.
84   * @permission ohos.permission.MANAGE_SECURE_SETTINGS
85   * @since 9
86   */
87  function enableNfc(): void
88
89  /**
90   * Disables NFC.
91   *
92   * @returns Returns {@code true} if NFC is disabled or has been disabled; returns {@code false} otherwise.
93   * @permission ohos.permission.MANAGE_SECURE_SETTINGS
94   * @since 7
95   * @deprecated since 9
96   * @useinstead @ohos.nfc.controller.nfcController#disableNfc
97   */
98  function closeNfc(): boolean
99
100  /**
101   * Disables NFC.
102   *
103   * @throws { BusinessError } 201 - Permission denied.
104   * @throws { BusinessError } 801 - Capability not supported.
105   * @throws { BusinessError } 3100101 - NFC state is abnormal in service.
106   * @permission ohos.permission.MANAGE_SECURE_SETTINGS
107   * @since 9
108   */
109   function disableNfc(): void
110
111  /**
112   * Checks whether NFC is enabled.
113   *
114   * @returns Returns {@code true} if NFC is enabled; returns {@code false} otherwise.
115   * @since 7
116   */
117  function isNfcOpen(): boolean
118
119  /**
120   * Obtains the NFC status.
121   *
122   * <p>The NFC status can be any of the following: <ul><li>{@link #STATE_OFF}: Indicates that NFC
123   * is disabled. <li>{@link #STATE_TURNING_ON}: Indicates that NFC is being enabled.
124   * <li>{@link #STATE_ON}: Indicates that NFC is enabled. <li>{@link #STATE_TURNING_OFF}: Indicates
125   * that NFC is being disabled.</ul>
126   *
127   * @returns Returns the NFC status.
128   * @since 7
129   */
130  function getNfcState(): NfcState
131}
132
133export default nfcController;
134