Creating a super generic NFC app for Windows Phone 8.1

In a recent project we had to create an Windows 8.1 NFC app to work with a specific pre-written tag band:- The challenge? The client had not identified the tag bracelet!. So although good code should work with all compatible tags, what if the the tags were bad??

NFC enabled Windows 8 works with only NDEF format tags .NDEF are NFC Data Exchange Format (NDEF) messages. You can find more information here: Understanding NFC Data Exchange Format (NDEF) messages.

So coming back to our problem:- We modified a sample app provided by Nokia such that it can read ALL windows compatible tags. Then we went shopping for tags with the new modified app…as long as the app could recognize the tag we knew we were good to go!

We downloaded the app from here. This app is pretty cool in that it shows us how to work with different NDEF tags like NDEFUriRecord, NdefTextRecord but if the tag simply transmits a non-formatted NDEF string then it gets missed by this app. Since we were using this app to test for compatibility, we needed to add the following block in the MessageReceivedHandler   method

 

 if(specializedType==typeof(NdefRecord))
                {
                    var contents = new NdefRecord(record);
                    var x = contents.ToString();
                    var y = contents.Payload;
                    string s = System.Text.Encoding.UTF8.GetString(y, 0, y.Length);
                    tagContents.AppendFormat("-> String is {0}\n",s);

                }

 

The tag bracelets we bought worked great with our final app and the project was a success!  Working with NFC was fun… We learnt a few more tricks and tips! More about that soon!! Till then get in touch with us if you are planning to use NFC in your next app!

Team Cennest!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>