title: Read Nfc tag on Windows 10 uwp
body: <p>So, I simply want to read the contents of an Nfc tag using my Windows 10 UWP app. I see that there are two Nfc samples in the Microsoft UWP samples on GitHub. However, I have tried those and they don't seem to work.</p>
  
  <p>So, as I was reading, I have found that I can use </p>
  
  <pre><code>Windows.Network.Proximity.ProximityDevice
  </code></pre>
  
  <p>To get the reader and then subscribe to read the NDEF message.</p>
  
  <p><a href="https://github.com/andijakl/ndef-nfc/blob/master/NdefDemo/NdefDemoWin10/MainPage.xaml.cs" rel="nofollow noreferrer">Using this example</a> I was able to write the following code:</p>
  
  <pre><code>private ProximityDevice proxDevice;
  private string proxDeviceId;
  private long _subscriptionIdNdef;
  private long _publishingMessageId;
  
  private void InitNfc()
  {
      proxDevice = ProximityDevice.GetDefault();
  
      if (proxDevice != null)
      {
          proxDeviceId = proxDevice.DeviceId;
          proxDevice.DeviceArrived += ProxDevice_DeviceArrived;
          proxDevice.DeviceDeparted += ProxDevice_DeviceDeparted;
          initSubscription();
      }
  }
  
  private void initSubscription()
  {
      if (_subscriptionIdNdef != 0) return;
  
      _subscriptionIdNdef = proxDevice.SubscribeForMessage("NDEF", MessageReceivedHandler);
  }
  
  private void MessageReceivedHandler(ProximityDevice sender, ProximityMessage message)
  {
      var rawMsg = message.DataAsString;
  }
  
  private void ProxDevice_DeviceDeparted(ProximityDevice sender)
  {
  
  }
  
  private void ProxDevice_DeviceArrived(ProximityDevice sender)
  {
  
  }
  </code></pre>
  
  <p>With this quick and dirty example, there are some good things happening. First, the proxDevice is not null and it does get a device. Second, I can read the device id of the proxDevice. The initSubscription call returns without exception which is good. So, at the surface, it seems all is good and ready to read the tag.</p>
  
  <p>However, when I approach a tag to the mobile device, I can get the two events "DeviceArrived" and "DeviceDeparted" to fire successfully, which is also good. The issue is, I cannot get the "MessageReceivedHandler" event to fire, ever.</p>
  
  <p>It would seem there is a subscription issue? But again, that method returns without exception. I saw another post where somebody said they had to change "NDEF" to "WindowsMime" which I tried, but again, the event never fires.</p>
  
  <p>EDIT - So, I was able to get the event to fire. If I subscribed to the message "WriteableTag" the event will raise. What I have learned so far is that this is a blank tag and therefore, it does not have an NDEF record yet. This would explain why subscribing to NDEF does not fire the event. That said, I have two options. First is to write NDEF to the tag and I should be good to go. However, second and most desirable is to just read the UID of the tag. So, can I read the UID of an NFC tag, even if it is blank and does not have and NDEF record yet? My requirements are that I want it to be simple and I don't need NDEF records, I just need a unique number, which the UID will give me. Can this be one on Windows 10 UWP?</p>
  
  <p>Any thoughts?</p>