O'Reilly logo

Xamarin Mobile Development for Android Cookbook by Matthew Leibowitz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required