Home > C#, WinRT > How to write an NFC tag that can start a Skype call with Windows 8

How to write an NFC tag that can start a Skype call with Windows 8

27/09/2013

The ProximityDevice class makes it easy to publish content that can be received by another NFC equipped devices or written to smart tags.

Among the other things, we can publish an Uri to a tag. The most interesting part is that we aren’t limited to Web address: http:// protocol launches browser and shows the specified URL, while other protocols launch apps registered for them and can include start arguments.

So, we can publish an Uri that, if read by a Windows 8 device, is able to start a Skype call to the passed contact:

private void WriteSkypeTag(string skypeName)
{
    var device = ProximityDevice.GetDefault();
    if (device != null)
    {
        using (var writer = new DataWriter { UnicodeEncoding = UnicodeEncoding.Utf16LE })
        {
            // Prepare the message to be published.
            var uri = string.Format("skype:{0}?call", skypeName);
            writer.WriteString(uri);
            var buffer = writer.DetachBuffer();                    

            // Publish the message. You must tap an NFC tag to your device to write 
            // the content to it.
            device.PublishBinaryMessage("WindowsUri:WriteTag", buffer, 
                async (sender, messageId) =>
                {
                    device.StopPublishingMessage(messageId);

                    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
                    {
                        var message = new MessageDialog
                            ("The Skype contact has been written to the tag.");
                        await message.ShowAsync();
                    });
                });
        }
    }
}

At line 9, we create an Uri using the Skype app activation protocol, for example skype:echo123?call (echo123 is the Skype name of the Echo / Sound Test Service contact). Then, at line 15, we publish the message. Specifying the type WindowsUri:WriteTag, we indicate that the content is an Uri and it can transmitted only to smart tag. The message will be written as soon as a tag is tapped to the device, and a popup dialog will be displayed when the procedure finishes.

Now, to start a Skype call to the contact that has been saved on the chip, we simply need to tap it to the device. Note that, at this moment, Windows Phone doesn’t support the Skype app activation protocol.

Categories: C#, WinRT
%d bloggers like this: