Friday, November 9, 2012

That damn NFC alert after tapping a tag on WP8

In these days I had the opportunity to develop a Windows Phone 8 application for my company.
The main reason we choose WP8 was the new Proximity API for reading NFC Tags.

I don't wanna write about how to read or write a NFC Tag but I just want to notify you an issue I encountered while developing.

When you tap a Tag over a device, a system dialog appears asking you if you want to view the content of the tag. A dialog is showed even if there aren't app that can manage a specified tag content.
So read a Tag brings an annoying system dialog.

I had to realize an app that reads tags during an event and does a check-in . So in a single page I want to read several nfc tags without any kind of interruptions.
Can I read a tag without seeing this damn alert that is literally ruining my UX? The answer is yes I can.

I followed the official specs for publish a message on a tag.
My target was to write a text/plain data, so I initially tried with "Windows:WriteTag.text/plain".
No way. While reading, inside or outside the app context, popup appears.
I also tried other mime-types, publishing a URI, a custom URI with a custom Protocol, I tried a FileTypeAssociation... nothing worked.

I don't know why... but this method worked for me and our Samsung ATIV S.
//-------------------------WRITING

var dataWriter = new Windows.Storage.Streams.DataWriter();
dataWriter.WriteString("dummy");

//messageType is the key
publishMessageId = mDevice.PublishBinaryMessage("Windows:WriteTag.Text",
                   dataWriter.DetachBuffer(), 
                   messageTransmitted);

//my MessageTransmittedHandler invokes the StopPublishingMessage(long) method

//-------------------------READING

mDevice.SubscribeForMessage("Windows.Text",
                            (device, message) =>
                            {
                               //do Work
                            });

Like a magic... No popup on my way :)

I hope I'll find soon an explanation for this, otherwise...

Happy coding 

3 comments:

  1. Cool, hate that dialogue ... offered your thoughts here, where people are asking for a solution:

    http://forums.wpcentral.com/nokia-lumia-928/227831-nfc-nag-screen.html#post2020827

    ReplyDelete
  2. Thank you for your resolution. Can you write easy guide how users must use your scrypt, because many people don't interested in programing.

    ReplyDelete