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:

  1. As with the other hardware features, we need permission to access NFC services:
    [assembly: UsesPermission(Manifest.Permission.Nfc)]
  2. 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 to true:
    [assembly: UsesFeature(
      PackageManager.FeatureNfc, Required = true)]

    However, if our app runs ...

Get Xamarin Mobile Development for Android Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.