Search code examples
c#windows-store-appswin-universal-appnfcuwp

Get notified when an NFC card is in range


How do I get notified when an arbitrary NFC card (any card with a chip) is in range of my Windows mobile phone? I have a Lumia 640 which has NFC capabilities.

Unfortunately, I've only found how to subscribe to a specific type of card using ProximityDevice.SubscribeForMessage which needs a messageType. I want a generic card reader. How do I do that?


Solution

  • The Proximity API only supports NDEF formatted tags. Thus it's not possible to detect "any card with chip". The closest you can get to that is to subscribe to any tag that contains a valid NDEF message (this essentially boils down to "any tag supported by the device"):

    subscribedMessageId = proximityDevice.SubscribeForMessage("NDEF", messageReceived);
    

    where proximityDevice is your instance of the ProximityDevice and messageReceived is the MessageReceivedHandler.

    Note that there also is the Smartcard API which can be used to enumerate and access certain contactless smartcards through the NFC reader.