Project Description
Easily parse and create NDEF records with the Windows Proximity APIs (NFC) for Windows 8 and Windows Phone 8.
The library download comes with an example app that demonstrates reading and writing tags using the NDEF Library.
Overview
The
Proximity APIs for NFC (Near Field Communication) in the Windows 8 platform are compatible to NDEF (NFC Data Exchange Format) messages, which are used on NFC tags and to send data between two devices.
While the Proximity APIs include basic support for URIs, they lack support for more in-depth control over the NDEF records, as well as additional standardized record types.
This NDEF Library provides a set of classes that enable you to easily work with NDEF records on top of the Windows Proximity APIs.
Integrate the library into your Windows 8 platform project using the NuGet package manager of Visual Studio. The portable class library is fully compatible to Windows 8 & Windows Phone 8.
To keep up to date, either follow this project or
follow me on Twitter.
Reusable NDEF classes
- Parse NDEF message & records from raw byte arrays
- Extract all information from the bits & bytes contained in the record
- Create standard compliant records just by providing your data
- Supports fully standardized basic record types:
- Smart URI class: automatically represents itself as the smallest possible NDEF type (URI or Smart Poster), depending on supplied data
- Convenience classes for:
- LaunchApp tags - launch a Windows (Phone) app just by tapping a tag
- Nokia Accessories tags - let the user choose an app to launch on his Nokia Lumia Windows Phone 8 device
- WpSettings tags - launch a settings page on Windows Phone 8 (e.g., Bluetooth settings, flight mode). Actually modifying these settings is not allowed by the security model of Windows Phone
- Android Application Record (AAR) tags - launch an Android app by tapping a tag
- Geo tags - longitude & latitude of a place, using different Geo URI schemes (more details)
- Social tags - linking to social networks like Twitter, Facebook, Foursquare or Skype
- SMS tags - defining number and body of the message
- Mailto tags - sending email messages with recipient address and optional subject and body
- Telephone call tags - defining the number to call
- NearSpeak tags - store voice messages on NFC tags, using the custom URI scheme as defined by the NearSpeak app: http://www.nearspeak.at/
- Records check their contents for validity according to standards
- Fully documented source code, following Doxygen standards
Example Apps
The
library download comes with NdefDemo, a Windows Phone 8 example app that demonstrates some of the features of the NDEF Library and is available under GPL v3 license.
Another GPL-licensed example app is
NfcShare, which is available together with accompagning webinar slides and a recording at the
NFC developer's section at NfcInteractor.com.
Examples of apps currently using the NDEF Library and available in the public store:
Usage example
Reading & parsing a Smart Poster
private void MessageReceivedHandler(ProximityDevice sender, ProximityMessage message)
{
// Parse raw byte array to NDEF message
var rawMsg = message.Data.ToArray();
var ndefMessage = NdefMessage.FromByteArray(rawMsg);
// Loop over all records contained in the NDEF message
foreach (NdefRecord record in ndefMessage)
{
Debug.WriteLine("Record type: " + Encoding.UTF8.GetString(record.Type, 0, record.Type.Length));
// Check the type of each record - handling a Smart Poster in this example
if (record.CheckSpecializedType(false) == typeof (NdefSpRecord))
{
// Convert and extract Smart Poster info
var spRecord = new NdefSpRecord(record);
Debug.WriteLine("URI: " + spRecord.Uri);
Debug.WriteLine("Titles: " + spRecord.TitleCount());
Debug.WriteLine("1. Title: " + spRecord.Titles[0].Text);
Debug.WriteLine("Action set: " + spRecord.ActionInUse());
}
}
}
Writing a Smart Poster
// Initialize Smart Poster record with URI, Action + 1 Title
var spRecord = new NdefSpRecord {
Uri = "http://www.nfcinteractor.com",
NfcAction = NdefSpActRecord.NfcActionType.DoAction };
spRecord.AddTitle(new NdefTextRecord {
Text = "Nfc Interactor", LanguageCode = "en" });
// Add record to NDEF message
var msg = new NdefMessage { spRecord };
// Publish NDEF message to a tag
// AsBuffer(): add -> using System.Runtime.InteropServices.WindowsRuntime;
_device.PublishBinaryMessage("NDEF:WriteTag", msg.ToByteArray().AsBuffer());
// Alternative: send NDEF message to another NFC device
_device.PublishBinaryMessage("NDEF", msg.ToByteArray().AsBuffer());
Installation
To try the library, you can download the
complete library package from this site and test the included NdefDemo example app (currently available for Windows Phone 8).
If you want to use the Ndef Library from your own app, the easiest option is to use the NuGet package manager in Visual Studio 2012 to automatically download & integrate the portable library:
- Ensure you have Nuget version >= 2.1
Update through: Tools -> Extensions and Updates... -> Updates (left sidebar) -> Visual Studio Gallery
(Otherwise, you will get an error message like this during installation:
Install failed. Rolling back... Could not install package 'NdefLibrary'. You are trying to install this package into a project that targets 'WindowsPhone,Version=v8.0', but the package does not contain any assembly references that are compatible with that
framework. For more information, contact the package author." - Tools -> Library Package Manager -> Manage NuGet Packages for Solution...
- Search "Online" for "NDEF"
- Install the "NDEF Library for Proximity APIs (NFC)"

More information: https://nuget.org/packages/NdefLibrary
Debug symbols:
http://www.symbolsource.org/Public/Metadata/NuGet/Project/NdefLibrary
You can also download the complete portable library project from the source control server of this project, and build the library yourself, or directly integrate the relevant class files.
Status & Roadmap
The NDEF library is classified as stable release and is in use in several projects, most importantly
Nfc Interactor for Windows Phone. For more information about any currently open issues as well as planned features, see the
issue tracker page.
The libraries are based on the respective code of the Connectivity Module of Qt Mobility (http://qt.gitorious.org/qt-mobility).