2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Collections.Generic;
19 using System.Threading.Tasks;
22 namespace Tizen.Network.Nfc
25 /// A class for the NFC management. It allows applications to use the NFC service.
27 /// <since_tizen> 3 </since_tizen>
28 /// <privilege>http://tizen.org/privilege/nfc</privilege>
29 static public class NfcManager
32 /// Checks whether the NFC is supported.
34 /// <since_tizen> 3 </since_tizen>
35 static public bool IsSupported
39 bool isNfcSupported = false;
41 SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
45 throw new NotSupportedException();
50 return NfcManagerImpl.Instance.IsSupported;
52 catch (TypeInitializationException e)
54 throw e.InnerException;
60 /// The NFC Activation state.
62 /// <since_tizen> 3 </since_tizen>
63 static public bool IsActivated
67 bool isNfcSupported = false;
69 SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
73 throw new NotSupportedException();
78 return NfcManagerImpl.Instance.IsActivated;
80 catch (TypeInitializationException e)
82 throw e.InnerException;
88 /// The Tag Filter type.
90 /// <since_tizen> 3 </since_tizen>
91 static public NfcTagFilterType TagFilterType
95 bool isNfcSupported = false;
96 bool isTagSupported = false;
98 SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
99 SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc.tag", out isTagSupported);
101 if (!isNfcSupported || !isTagSupported)
103 throw new NotSupportedException();
108 return NfcManagerImpl.Instance.TagFilterType;
110 catch (TypeInitializationException e)
112 throw e.InnerException;
117 bool isNfcSupported = false;
118 bool isTagSupported = false;
120 SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
121 SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc.tag", out isTagSupported);
123 if (!isNfcSupported || !isTagSupported)
125 throw new NotSupportedException();
130 NfcManagerImpl.Instance.TagFilterType = value;
132 catch (TypeInitializationException e)
134 throw e.InnerException;
140 /// The Secure Element type.
142 /// <since_tizen> 3 </since_tizen>
143 /// <privilege>http://tizen.org/privilege/nfc.cardemulation</privilege>
144 static public NfcSecureElementType SecureElementType
148 bool isNfcSupported = false;
149 bool isCeSupported = false;
151 SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
152 SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc.cardemulation", out isCeSupported);
154 if (!isNfcSupported || !isCeSupported)
156 throw new NotSupportedException();
161 return NfcManagerImpl.Instance.SecureElementType;
163 catch (TypeInitializationException e)
165 throw e.InnerException;
170 bool isNfcSupported = false;
171 bool isCeSupported = false;
173 SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
174 SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc.cardemulation", out isCeSupported);
176 if (!isNfcSupported || !isCeSupported)
178 throw new NotSupportedException();
183 NfcManagerImpl.Instance.SecureElementType = value;
185 catch (TypeInitializationException e)
187 throw e.InnerException;
193 /// Enables or disables the system handling for the tag and target discovered event.
195 /// <since_tizen> 3 </since_tizen>
196 /// <privilege>http://tizen.org/privilege/nfc</privilege>
197 static public bool SystemHandlerEnabled
201 bool isNfcSupported = false;
203 SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
207 throw new NotSupportedException();
212 return NfcManagerImpl.Instance.SystemHandlerEnabled;
214 catch (TypeInitializationException e)
216 throw e.InnerException;
221 bool isNfcSupported = false;
223 SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
227 throw new NotSupportedException();
232 NfcManagerImpl.Instance.SystemHandlerEnabled = value;
234 catch (TypeInitializationException e)
236 throw e.InnerException;
242 /// The cached NDEF message.
244 /// <since_tizen> 3 </since_tizen>
245 static public NfcNdefMessage CachedNdefMessage
249 bool isNfcSupported = false;
251 SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
255 throw new NotSupportedException();
260 return NfcManagerImpl.Instance.CachedNdefMessage;
262 catch (TypeInitializationException e)
264 throw e.InnerException;
270 /// Gets the Tag adapter object.
272 /// <since_tizen> 3 </since_tizen>
273 static public NfcTagAdapter GetTagAdapter()
275 bool isNfcSupported = false;
276 bool isTagSupported = false;
278 SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
279 SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc.tag", out isTagSupported);
281 if (!isNfcSupported || !isTagSupported)
283 throw new NotSupportedException();
288 return NfcManagerImpl.Instance.TagAdapter;
290 catch (TypeInitializationException e)
292 throw e.InnerException;
297 /// Gets the P2P adapter object.
299 /// <since_tizen> 3 </since_tizen>
300 static public NfcP2pAdapter GetP2pAdapter()
302 bool isNfcSupported = false;
303 bool isP2pSupported = false;
305 SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
306 SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc.p2p", out isP2pSupported);
308 if (!isNfcSupported || !isP2pSupported)
310 throw new NotSupportedException();
315 return NfcManagerImpl.Instance.P2pAdapter;
317 catch (TypeInitializationException e)
319 throw e.InnerException;
324 /// Gets the Card Emulation adapter object.
326 /// <since_tizen> 3 </since_tizen>
327 static public NfcCardEmulationAdapter GetCardEmulationAdapter()
329 bool isNfcSupported = false;
330 bool isCeSupported = false;
332 SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
333 SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc.cardemulation", out isCeSupported);
335 if (!isNfcSupported || !isCeSupported)
337 throw new NotSupportedException();
342 return NfcManagerImpl.Instance.CardEmulationAdapter;
344 catch (TypeInitializationException e)
346 throw e.InnerException;
351 /// Activates the NFC asynchronously.
353 /// <since_tizen> 3 </since_tizen>
354 /// <returns>A task indicates whether the Activate method is done or not.</returns>
355 /// <privilege>http://tizen.org/privilege/nfc.admin</privilege>
356 static public Task SetActivationAsync(bool activation)
358 bool isNfcSupported = false;
360 SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
364 throw new NotSupportedException();
369 return NfcManagerImpl.Instance.SetActivationAsync(activation);
371 catch (TypeInitializationException e)
373 throw e.InnerException;
378 /// The Activation changed event.
380 /// <since_tizen> 3 </since_tizen>
381 static public event EventHandler<ActivationChangedEventArgs> ActivationChanged
385 bool isNfcSupported = false;
387 SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
391 throw new NotSupportedException();
396 NfcManagerImpl.Instance.ActivationChanged += value;
398 catch (TypeInitializationException e)
400 throw e.InnerException;
405 bool isNfcSupported = false;
407 SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
411 throw new NotSupportedException();
416 NfcManagerImpl.Instance.ActivationChanged -= value;
418 catch (TypeInitializationException e)
420 throw e.InnerException;
426 /// The NDEF discovered event.
428 /// <since_tizen> 3 </since_tizen>
429 static public event EventHandler<NdefMessageDiscoveredEventArgs> NdefMessageDiscovered
433 bool isNfcSupported = false;
435 SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
439 throw new NotSupportedException();
444 NfcManagerImpl.Instance.NdefMessageDiscovered += value;
446 catch (TypeInitializationException e)
448 throw e.InnerException;
453 bool isNfcSupported = false;
455 SystemInfo.TryGetValue("http://tizen.org/feature/network.nfc", out isNfcSupported);
459 throw new NotSupportedException();
464 NfcManagerImpl.Instance.NdefMessageDiscovered -= value;
466 catch (TypeInitializationException e)
468 throw e.InnerException;