Monday, April 22, 2013

Develop a cutting edge app with NFC

Inline image 2

Near Field Communication (NFC) is an emerging, short range wireless technology. With a precise range of 2 cm, people can physically tap devices together to send/receive content. Tapping lets you select something (or someone) quickly. Not only is it quick, it's also easy to understand. Once you see it, you get it; there's no manual needed.

For example, imagine you are looking at some photos with a friend and she wants your pictures; with NFC, you can simply tap your device against her PC to send the photos. Over simplifying? Maybe, but the main idea is that it's simple to share content between devices.

...
...

The next code snippet shows how to initialize and add a DeviceArrival event handler.

C#
private void InitializeProximityDevice()
{

Windows.Networking.Proximity.ProximityDevice proximityDevice;
    proximityDevice = Windows.Networking.Proximity.ProximityDevice.GetDefault();

    if (proximityDevice != null) {
        proximityDevice.DeviceArrived += ProximityDeviceArrived;
    
    }
    else
    {
        // No NFC radio on the PC, display an error message
    }
}

private void ProximityDeviceArrived(Windows.Networking.Proximity.ProximityDevice device)
{
            // Let the user know we're 'Writing to Tag'

}

Next, we publish information to the tag. The app publishes two things: an app identifier string, which consists of an app ID and app platform, and launch arguments. For Windows 8, the app Id is <package family name>!<app Id> and the app platform is 'Windows.' You must copy the app ID value from the ID attribute of the Application element in the package manifest for your app. The launch argument is '07:00' – the alarm set by the user. Let's call this the message.

QR: Inline image 1