Receiving NFC events
Sometimes we may wish to make use of NFC, a very short range communication technology, to transfer data or to interact with NFC tags.
Getting ready
To develop for NFC, we need to have a device that includes NFC hardware.
How to do it…
We can query the NfcAdapter
instance for the status of the hardware as well as to be notified when a new tag is detected:
As with the other hardware features, we need permission to access NFC services:
[assembly: UsesPermission(Manifest.Permission.Nfc)]
Additionally, we need to specify that we are going to be using the NFC device feature. If our app cannot run without NFC, we set the
Required
property totrue
:[assembly: UsesFeature( PackageManager.FeatureNfc, Required = true)]
However, if our app runs fine on a device without NFC, we set the
Required
property tofalse
:[assembly: UsesFeature( PackageManager.FeatureNfc, Required = false)]
Now that we have permission, we can get the
NfcAdapter
instance:adapter = NfcAdapter.GetDefaultAdapter(this...