SlideShare a Scribd company logo
Windows 8 Platform
NFC Development
Andreas Jakl, Mopius

Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl
NFC Forum and the NFC Forum logo are trademarks of the Near Field Communication Forum.

1
Andreas Jakl
Twitter: @mopius
Email: andreas.jakl@mopius.com
Trainer & app developer
– mopius.com
– nfcinteractor.com

Nokia: Technology Wizard
FH Hagenberg, Mobile Computing: Assistant Professor
Siemens / BenQ Mobile: Augmented Reality-Apps
Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

2
We’re covering
Windows (Phone) 8 Proximity APIs
Based on MSDN documentation
bit.ly/ProximityAPI
bit.ly/ProximityAPIwp8
bit.ly/ProximitySpec

Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

3
Tap and Do
A gesture that is a natural interaction between people in close proximity used
to trigger doing something together between the devices they are holding.

System: Near Field Proximity
(e.g., NFC)

Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl
Documentation: bit.ly/ProximitySpec

4
NFC Scenarios

Connect Devices

Exchange Digital Objects

Acquire Content

Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

5
From Tags and Peers

ACQUIRE CONTENT
Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

6
Acquire Content Scenarios
Website link (e.g., company)

Laulujoutsen
Whooper Swan
National bird of Finland,
on €1 coin

More information (e.g., museum, concert)

Custom app extensions (e.g., bonus item for a game)
Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl
Angry Birds © Rovio

7
Get Started: Read URIs via NFC
ProximityDevice
Connect to HW
Detect devices in range
Publish & subscribe to messages

ProximityMessage
Contents of received message

Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

8
Proximity Capability

Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

9
URI Subscriptions
1 Activate proximity device
_device = ProximityDevice.GetDefault();

2 Subscribe to URI messages
_subscribedMessageId = _device.SubscribeForMessage(
"WindowsUri", MessageReceivedHandler);

3 Handle messages
private void MessageReceivedHandler(ProximityDevice sender,
ProximityMessage message) {
var msgArray = message.Data.ToArray();
var url = Encoding.Unicode.GetString(msgArray, 0, msgArray.Length);
Debug.WriteLine("URI: " + url);
}
Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl
API documentation: bit.ly/ProximityAPI

10
URI Subscriptions
Smart Poster
WindowsUri
URI

4 Cancel subscriptions
_subscribedMessageId = _device.SubscribeForMessage(…);
_device.StopSubscribingForMessage(_subscribedMessageId);
Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl
API documentation: bit.ly/ProximityAPI

11
Publish & Write

SPREAD THE WORD
Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

12
Publish Messages
1 Start publishing
_publishingMessageId = _device.PublishUriMessage(
new Uri("nfcinteractor:compose"));

Proximity devices only
– (doesn’t write tags)

Contains
scheme,
platform &
App ID

Windows Protocol + URI record
– Encapsulated in NDEF

Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

13
Write Tags
1 Prepare & convert data
var dataWriter = 
new Windows.Storage.Streams.DataWriter { 
UnicodeEncoding = Windows.Storage.Streams.
UnicodeEncoding.Utf16LE};
dataWriter.WriteString("nfcinteractor:compose");
var dataBuffer = dataWriter.DetachBuffer();

Mandatory
encoding

2 Write tag (no device publication)
_device.PublishBinaryMessage("WindowsUri:WriteTag", dataBuffer);

bit.ly/PublishTypes
Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

14
Tag Size?
1 Subscribe for writable tag info
_device.SubscribeForMessage("WriteableTag", 
MessageReceivedHandler);

2 Check maximum writable tag size in handler
var tagSize = BitConverter.ToInt32(message.Data.ToArray(), 0);
Debug.WriteLine("Writeable tag size: " + tagSize);

3 Device HW capabilities
var bps = _device.BitsPerSecond;
var mmb = _device.MaxMessageBytes;

// >= 16kB/s
// >= 10kB

Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl
API documentation: bit.ly/ProximityAPI

15
Standardized NFC Tag Contents

NDEF HANDLING
Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

16
Data on an NFC Tag
LaunchApp
Arguments
[speech text]
WindowsPhone app ID
{0450eab3-92…}

Data
NDEF Record(s)

Encapsulated in
NDEF Message

Encoded through
NFC Forum
Tag Type Platform

Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl
NDEF = NFC Data Exchange Format, Container image adapted from s_volenszki (Flickr), released under Creative Commons BY-NC 2.0

Stored on
NFC Forum Tag

17
Reading NDEF
1 Subscribe to all NDEF messages
_subscribedMessageId = _device.SubscribeForMessage(
"NDEF", MessageReceivedHandler);

2 Parse raw byte array in handler 

http://www.nfc-forum.org/specs/

Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

18
Reading NDEF
// Convert the language code to a byte array

Simple example:
assembling payload of Text record

1 Subscribe to all NDEF messages= Encoding.UTF8;
var languageEncoding

var encodedLanguage = languageEncoding.GetBytes(languageCode);
// Encode and convert the text to a byte array
var encoding = (textEncoding == TextEncodingType.Utf8) ? Encoding.UTF8 : Encoding.BigEndianUnicode;
var encodedText = encoding.GetBytes(text);
// Calculate the length of the payload & create the array
var payloadLength = 1 + encodedLanguage.Length + encodedText.Length;
Payload = new byte[payloadLength];

_subscribedMessageId = _device.SubscribeForMessage(
"NDEF", MessageReceivedHandler);

2 Parse raw byte array in handler 

// Assemble the status byte
Payload[0] = 0; // Make sure also the RFU bit is set to 0
// Text encoding
if (textEncoding == TextEncodingType.Utf8)
Payload[0] &= 0x7F; // ~0x80
else
Payload[0] |= 0x80;

http://www.nfc-forum.org/specs/

// Language code length
Payload[0] |= (byte)(0x3f & (byte)encodedLanguage.Length);
// Language code
Array.Copy(encodedLanguage, 0, Payload, 1, encodedLanguage.Length);
// Text
Array.Copy(encodedText, 0, Payload, 1 + encodedLanguage.Length, encodedText.Length);

Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

19
Windows 8 & Windows Phone 8

NFC / NDEF LIBRARY FOR PROXIMITY APIS
Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

20
NDEF.codeplex.com
Create NDEF
messages & records
(standard compliant)

Reusable
NDEF classes

Parse information
from raw byte arrays

Fully documented
Open Source LGPL license
(based on Qt Mobility)

Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

21
NDEF Subscriptions
1 Subscribe to all NDEF formatted tags
_subscribedMessageId = _device.SubscribeForMessage("NDEF",
MessageReceivedHandler);

2 Parse NDEF message
private void MessageReceivedHandler(ProximityDevice sender, 
ProximityMessage message)
{
var msgArray = message.Data.ToArray();
NdefMessage ndefMessage = NdefMessage.FromByteArray(msgArray);
[...]
}
Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

22
NDEF Subscriptions
3 Analyze all contained NDEF records with specialized classes
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());
}
}
Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

23
Write NDEF
1 Prepare & convert data
// Initialize Smart Poster record with URI, Action + 1 Title
var spRecord = new NdefSpRecord
{ Uri = "http://www.nfcinteractor.com" };
spRecord.AddTitle(new NdefTextRecord
{ Text = "Nfc Interactor", LanguageCode = "en" });
// Add record to NDEF message
var msg = new NdefMessage { spRecord };

2a Write tag
// Publish NDEF message to a tag
_device.PublishBinaryMessage("NDEF:WriteTag", msg.ToByteArray().AsBuffer());

2b Publish to devices
// Alternative: send NDEF message to another NFC device
_device.PublishBinaryMessage("NDEF", msg.ToByteArray().AsBuffer());
Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

24
APP LAUNCHING
Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

25
App Launch Scenarios
Discover your app

Share app to other users

Create seamless multi-user experience
Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

26
App Launching Summary
Register for

Files

URI protocol

LaunchApp
Tag

Peer to Peer

User opens
particular file

Tag launches app
through custom
URI scheme

Tag directly contains
app name and
parameters

App requests peer
device to start
the same app

Not so relevant for NFC

Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

27
How to Launch Apps

either or

Win8 + WP8

Tag directly contains
app name and
custom data.
No registration necessary.

Custom URI scheme
launches app.
App needs to register.

Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

28
nearspeak: Good+morning.
Protocol
name

Custom
data
Encoded Launch URI
Examples*
skype:mopius?call
spotify:search:17th%20boulevard

Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl
* Definition & examples: http://en.wikipedia.org/wiki/URI_scheme

29
User Experience

No app installed

1 app installed

2+ apps installed

Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

30
WP Protocol Association

Note: different
in Win8 / WP8

1 Specify protocol name in WMAppManifest.xml
...</Tokens>
Protocol
<Extensions>
name
<Protocol Name="nearspeak"
NavUriFragment="encodedLaunchUri=%s"
TaskID="_default" />
Fixed
</Extensions>

Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

31
WP Protocol Association

Note: different
in Win8 / WP8

2 Create UriMapper class to parse parameters
class NearSpeakUriMapper : UriMapperBase
{
public override Uri MapUri(Uri uri)
{
// Example: "Protocol?encodedLaunchUri=nearspeak:Good+morning."
var tempUri = HttpUtility.UrlDecode(uri.ToString());
var launchContents = Regex.Match(tempUri, @"nearspeak:(.*)$").Groups[1].Value;
if (!String.IsNullOrEmpty(launchContents))
{
// Launched from associated "nearspeak:" protocol
// Call MainPage.xaml with parameters
return new Uri("/MainPage.xaml?ms_nfp_launchargs=" + launchContents, UriKind.Relative);
}
// Include the original URI with the mapping to the main page
return uri;
}}

Argument already handled in step 9 of LaunchApp
tags (MainPage.OnNavigatedTo)

Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

32
WP Protocol Association
3 Use UriMapper in App.xaml.cs
(region:

)

private void InitializePhoneApplication() {
RootFrame = new PhoneApplicationFrame();
RootFrame.UriMapper = new NearSpeakUriMapper();
}

– If needed: launch protocol from app (for app2app comm)
await Windows.System.Launcher.LaunchUriAsync(
new Uri("nearspeak:Good+morning."));

Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

33
bit.ly/AppLaunching

Windows 8 Protocol Association

Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

34
parameters

platform 1

app name 1

platform 2

app name 2

…

Encoded into NDEF message*

Directly launch App
Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl
* For your low-level interest: type: Absolute URI, type name format: windows.com/LaunchApp. Contents re-formatted, e.g., with string lengths before each value

35
Write LaunchApp Tags

Note: different
in Win8 / WP8

1 Launch parameters, platforms + app IDs (note: Win8/WP8 ID format differences)
var launchArgs = "user=default";   // Can be empty
// The app's product id from the app manifest, wrapped in {}
var productId = "{xxx}"; 
var launchAppMessage = launchArgs + "tWindowsPhonet" + productId;

2 Convert to byte array
var dataWriter = new Windows.Storage.Streams.DataWriter
{UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf16LE};   
dataWriter.WriteString(launchAppMessage); 

3 Write to tags
_device.PublishBinaryMessage("LaunchApp:WriteTag",
dataWriter.DetachBuffer());
Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

36
PEER TO PEER
Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

37
Seamless MultiUser Games &
Collaboration

Tap for

Quick Data
Exchange

Long Term
Connection

ProximityDevice

PeerFinder

Exchange Windows /
NDEF messages,
SNEP protocol

Automatically builds
Bt / WiFi Direct
socket connection

Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

38
Establishing

Trigger

Long Term
Connection
Browse

Interact with Tap

Start Search

NFC

Bt, WiFi, etc.

Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

39
Tap to Trigger

App not installed

App installed
Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

40
Connection State
Proximity gesture complete
Devices can be pulled away

Which device initiated tap gesture?
→ Connecting, other device Listening

1
PeerFound

2
Connecting /
Listening

Access socket of persistent transport
(e.g., TCP/IP, Bt)

3
Completed

Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

41
Find Peers
1 Start waiting for triggered connections
PeerFinder.TriggeredConnectionStateChanged +=
TriggeredConnectionStateChanged;
PeerFinder.Start();

2 Peer found & connection established? Send message over socket
private async void TriggeredConnectionStateChanged(object sender, 
TriggeredConnectionStateChangedEventArgs eventArgs) {
if (eventArgs.State == TriggeredConnectState.Completed) {
// Socket connection established!
var dataWriter = new DataWriter(eventArgs.Socket.OutputStream);
dataWriter.WriteString("Hello Peer!");
var numBytesWritten = await dataWriter.StoreAsync();
3
}}
Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl
* For URI records + simple Smart Poster (w/o title), use the WindowsUri type.

42
Completed
UX Recommendations*
User initiated peer
search only

Ask for consent

Show connection
state

Failed
connection?
Inform & revert to
single-user mode

Let user get out of
proximity
experience

Proximity: only if
connection details
not relevant

Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl
* bit.ly/ProximityUX

43
NFC Tools
Proximity Tapper for WP emulator
– http://proximitytapper.codeplex.com/

Open NFC Simulator
– http://open-nfc.org/wp/editions/android/

NFC plugin for Eclipse: NDEF Editor
– https://code.google.com/p/nfc-eclipse-plugin/
Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

44
nfcinteractor.com

Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

45
NFC Resources
 NFC News: nfcworld.com
 NFC developer comparison
(WP, Android, BlackBerry):
bit.ly/NfcDevCompare
 Specifications: nfc-forum.org
Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

46
Thank You.
Andreas Jakl
@mopius
mopius.com
nfcinteractor.com

Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl

47

More Related Content

PDF
Windows Phone 8 NFC Quickstart
PDF
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?
PDF
Embedded Systems Security News 2011/06
PDF
Embedded Systems Security News 2011/05
PDF
Android HCE: An intro into the world of NFC
PDF
NFC Everywhere Brochure 2016
PDF
Ganesh
PDF
State of the Market
Windows Phone 8 NFC Quickstart
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?
Embedded Systems Security News 2011/06
Embedded Systems Security News 2011/05
Android HCE: An intro into the world of NFC
NFC Everywhere Brochure 2016
Ganesh
State of the Market

What's hot (20)

PDF
Electronic Access Control Security
PDF
NFC Development with Qt - v2.2.0 (5. November 2012)
PDF
Ultrabook Development Using Sensors - Intel AppLab Berlin
PPT
Civintec introduction 2015
PDF
Identive Group | Press Release | Identive Group's RFID and Near Field Communi...
PDF
NXP MIFARE Webinar: Innovation Road Map: Present Improved- Future Inside
PPT
NFC Basic Concepts
PDF
Near Field Communication (NFC)
PDF
Wireless Patents for Standards & Applications 1Q 2015
KEY
NFC & RFID on Android
PDF
VISIONFC Automotive Summit
PDF
Smart Phone in 2013
PPTX
Android Basic Presentation (Introduction)
PDF
Automating Your Life: A look at NFC
PDF
Nfc forum 14_feb07_press_and_analyst_briefing_slides
PDF
Embedded systems security news mar 2011
PDF
RFID2015_NFC-WISP_public(delete Disney research)
PPTX
NFC: Shaping the Future of the Connected Customer Experience
PDF
Near field communication
PDF
Nfc power point
Electronic Access Control Security
NFC Development with Qt - v2.2.0 (5. November 2012)
Ultrabook Development Using Sensors - Intel AppLab Berlin
Civintec introduction 2015
Identive Group | Press Release | Identive Group's RFID and Near Field Communi...
NXP MIFARE Webinar: Innovation Road Map: Present Improved- Future Inside
NFC Basic Concepts
Near Field Communication (NFC)
Wireless Patents for Standards & Applications 1Q 2015
NFC & RFID on Android
VISIONFC Automotive Summit
Smart Phone in 2013
Android Basic Presentation (Introduction)
Automating Your Life: A look at NFC
Nfc forum 14_feb07_press_and_analyst_briefing_slides
Embedded systems security news mar 2011
RFID2015_NFC-WISP_public(delete Disney research)
NFC: Shaping the Future of the Connected Customer Experience
Near field communication
Nfc power point
Ad

Viewers also liked (20)

PPTX
NFC Forum Tap Into NFC Developer Event
PDF
Embedded Systems Security News Feb 2011
PPT
Thinaire deck redux
PPTX
EE Reports Metering 101 Guide: Benefits and Applications of Submetering
PPTX
Making Waves with NFC 2011
PDF
Contextually Relevant Retail APIs for Dynamic Insights & Experiences
PDF
Is there such a thing as smart retail
PPTX
NFC for the Internet of Things
PPTX
NFC Bootcamp Seattle Day 2
PDF
Global tag portfolio_2015
PDF
System Label Company Overview
PDF
Product catalogue europe en_2016
PDF
Nokia NFC Presentation
PPTX
Hacking Tizen : The OS of Everything - Nullcon Goa 2015
PPT
NFC and consumers - Success factors and limitations in retail business - Flor...
PPTX
NEAR FIELD COMMUNICATION (NFC)
PDF
Recruter, Fidéliser dans vos magasins avec les technologies disruptives, iBea...
PDF
Track 1 session 6 - st dev con 2016 - smart badge
PDF
RFID/NFC for the Masses
PDF
CONNECTED OBJECTS - how NFC technology enables a more environmentally-friendl...
NFC Forum Tap Into NFC Developer Event
Embedded Systems Security News Feb 2011
Thinaire deck redux
EE Reports Metering 101 Guide: Benefits and Applications of Submetering
Making Waves with NFC 2011
Contextually Relevant Retail APIs for Dynamic Insights & Experiences
Is there such a thing as smart retail
NFC for the Internet of Things
NFC Bootcamp Seattle Day 2
Global tag portfolio_2015
System Label Company Overview
Product catalogue europe en_2016
Nokia NFC Presentation
Hacking Tizen : The OS of Everything - Nullcon Goa 2015
NFC and consumers - Success factors and limitations in retail business - Flor...
NEAR FIELD COMMUNICATION (NFC)
Recruter, Fidéliser dans vos magasins avec les technologies disruptives, iBea...
Track 1 session 6 - st dev con 2016 - smart badge
RFID/NFC for the Masses
CONNECTED OBJECTS - how NFC technology enables a more environmentally-friendl...
Ad

Similar to Windows 8 Platform NFC Development (20)

PDF
Windows (Phone) 8 NFC App Scenarios
PPTX
02 dev room6__tapand_go_jeffprosise_9Tap and Go: Proximity Networking in WinRT
PPTX
Nfc in wp8
PPTX
NFC for Windows Phone Developers, Microsoft MVP & Community Day, 18 June Mosc...
PPTX
Near field communication(NFC)
PDF
LUMIA APP LABS: DEVELOPING NFC APPS IN WINDOWS PHONE 8
PPTX
NFC (Windows 8/ Windows Phone 8 )
PDF
DefCon 2012 - Near-Field Communication / RFID Hacking - Miller
PPTX
NFC TECHNOLOGY
PDF
Introduction to nfc_v1_1_en
PDF
Introduction to nfc_v1_1_en
PPTX
Near field communication(nfc)
PPTX
Developing NFC Apps
PDF
NFC based services for Android platform
PDF
NFC-based User Interfaces
PPT
Introduction to nfc
PDF
NFC and the Salesforce Mobile SDK
PPTX
Near field communication
PPTX
Near field communication
PPTX
Nfc on Android
Windows (Phone) 8 NFC App Scenarios
02 dev room6__tapand_go_jeffprosise_9Tap and Go: Proximity Networking in WinRT
Nfc in wp8
NFC for Windows Phone Developers, Microsoft MVP & Community Day, 18 June Mosc...
Near field communication(NFC)
LUMIA APP LABS: DEVELOPING NFC APPS IN WINDOWS PHONE 8
NFC (Windows 8/ Windows Phone 8 )
DefCon 2012 - Near-Field Communication / RFID Hacking - Miller
NFC TECHNOLOGY
Introduction to nfc_v1_1_en
Introduction to nfc_v1_1_en
Near field communication(nfc)
Developing NFC Apps
NFC based services for Android platform
NFC-based User Interfaces
Introduction to nfc
NFC and the Salesforce Mobile SDK
Near field communication
Near field communication
Nfc on Android

More from Andreas Jakl (20)

PDF
Create Engaging Healthcare Experiences with Augmented Reality
PDF
AR / VR Interaction Development with Unity
PDF
Android Development with Kotlin, Part 3 - Code and App Management
PDF
Android Development with Kotlin, Part 2 - Internet Services and JSON
PDF
Android Development with Kotlin, Part 1 - Introduction
PDF
Android and NFC / NDEF (with Kotlin)
PDF
Basics of Web Technologies
PDF
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & More
PDF
Mobile Test Automation
PDF
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
PDF
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
PDF
Nokia New Asha Platform Developer Training
PDF
06 - Qt Communication
PDF
05 - Qt External Interaction and Graphics
PDF
04 - Qt Data
PDF
03 - Qt UI Development
PDF
02 - Basics of Qt
PDF
Basics of WRT (Web Runtime)
PDF
Java ME - Introduction
PDF
Intro - Forum Nokia & Mobile User Experience
Create Engaging Healthcare Experiences with Augmented Reality
AR / VR Interaction Development with Unity
Android Development with Kotlin, Part 3 - Code and App Management
Android Development with Kotlin, Part 2 - Internet Services and JSON
Android Development with Kotlin, Part 1 - Introduction
Android and NFC / NDEF (with Kotlin)
Basics of Web Technologies
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & More
Mobile Test Automation
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
Nokia New Asha Platform Developer Training
06 - Qt Communication
05 - Qt External Interaction and Graphics
04 - Qt Data
03 - Qt UI Development
02 - Basics of Qt
Basics of WRT (Web Runtime)
Java ME - Introduction
Intro - Forum Nokia & Mobile User Experience

Recently uploaded (20)

PPTX
MYSQL Presentation for SQL database connectivity
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
Approach and Philosophy of On baking technology
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Empathic Computing: Creating Shared Understanding
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
Machine learning based COVID-19 study performance prediction
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
KodekX | Application Modernization Development
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Cloud computing and distributed systems.
MYSQL Presentation for SQL database connectivity
Mobile App Security Testing_ A Comprehensive Guide.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
cuic standard and advanced reporting.pdf
Approach and Philosophy of On baking technology
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Empathic Computing: Creating Shared Understanding
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Spectroscopy.pptx food analysis technology
Machine learning based COVID-19 study performance prediction
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
KodekX | Application Modernization Development
“AI and Expert System Decision Support & Business Intelligence Systems”
The AUB Centre for AI in Media Proposal.docx
Understanding_Digital_Forensics_Presentation.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Cloud computing and distributed systems.

Windows 8 Platform NFC Development

  • 1. Windows 8 Platform NFC Development Andreas Jakl, Mopius Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl NFC Forum and the NFC Forum logo are trademarks of the Near Field Communication Forum. 1
  • 2. Andreas Jakl Twitter: @mopius Email: andreas.jakl@mopius.com Trainer & app developer – mopius.com – nfcinteractor.com Nokia: Technology Wizard FH Hagenberg, Mobile Computing: Assistant Professor Siemens / BenQ Mobile: Augmented Reality-Apps Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 2
  • 3. We’re covering Windows (Phone) 8 Proximity APIs Based on MSDN documentation bit.ly/ProximityAPI bit.ly/ProximityAPIwp8 bit.ly/ProximitySpec Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 3
  • 4. Tap and Do A gesture that is a natural interaction between people in close proximity used to trigger doing something together between the devices they are holding. System: Near Field Proximity (e.g., NFC) Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl Documentation: bit.ly/ProximitySpec 4
  • 5. NFC Scenarios Connect Devices Exchange Digital Objects Acquire Content Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 5
  • 6. From Tags and Peers ACQUIRE CONTENT Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 6
  • 7. Acquire Content Scenarios Website link (e.g., company) Laulujoutsen Whooper Swan National bird of Finland, on €1 coin More information (e.g., museum, concert) Custom app extensions (e.g., bonus item for a game) Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl Angry Birds © Rovio 7
  • 8. Get Started: Read URIs via NFC ProximityDevice Connect to HW Detect devices in range Publish & subscribe to messages ProximityMessage Contents of received message Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 8
  • 9. Proximity Capability Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 9
  • 10. URI Subscriptions 1 Activate proximity device _device = ProximityDevice.GetDefault(); 2 Subscribe to URI messages _subscribedMessageId = _device.SubscribeForMessage( "WindowsUri", MessageReceivedHandler); 3 Handle messages private void MessageReceivedHandler(ProximityDevice sender, ProximityMessage message) { var msgArray = message.Data.ToArray(); var url = Encoding.Unicode.GetString(msgArray, 0, msgArray.Length); Debug.WriteLine("URI: " + url); } Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl API documentation: bit.ly/ProximityAPI 10
  • 11. URI Subscriptions Smart Poster WindowsUri URI 4 Cancel subscriptions _subscribedMessageId = _device.SubscribeForMessage(…); _device.StopSubscribingForMessage(_subscribedMessageId); Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl API documentation: bit.ly/ProximityAPI 11
  • 12. Publish & Write SPREAD THE WORD Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 12
  • 13. Publish Messages 1 Start publishing _publishingMessageId = _device.PublishUriMessage( new Uri("nfcinteractor:compose")); Proximity devices only – (doesn’t write tags) Contains scheme, platform & App ID Windows Protocol + URI record – Encapsulated in NDEF Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 13
  • 14. Write Tags 1 Prepare & convert data var dataWriter =  new Windows.Storage.Streams.DataWriter {  UnicodeEncoding = Windows.Storage.Streams. UnicodeEncoding.Utf16LE}; dataWriter.WriteString("nfcinteractor:compose"); var dataBuffer = dataWriter.DetachBuffer(); Mandatory encoding 2 Write tag (no device publication) _device.PublishBinaryMessage("WindowsUri:WriteTag", dataBuffer); bit.ly/PublishTypes Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 14
  • 15. Tag Size? 1 Subscribe for writable tag info _device.SubscribeForMessage("WriteableTag",  MessageReceivedHandler); 2 Check maximum writable tag size in handler var tagSize = BitConverter.ToInt32(message.Data.ToArray(), 0); Debug.WriteLine("Writeable tag size: " + tagSize); 3 Device HW capabilities var bps = _device.BitsPerSecond; var mmb = _device.MaxMessageBytes; // >= 16kB/s // >= 10kB Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl API documentation: bit.ly/ProximityAPI 15
  • 16. Standardized NFC Tag Contents NDEF HANDLING Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 16
  • 17. Data on an NFC Tag LaunchApp Arguments [speech text] WindowsPhone app ID {0450eab3-92…} Data NDEF Record(s) Encapsulated in NDEF Message Encoded through NFC Forum Tag Type Platform Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl NDEF = NFC Data Exchange Format, Container image adapted from s_volenszki (Flickr), released under Creative Commons BY-NC 2.0 Stored on NFC Forum Tag 17
  • 18. Reading NDEF 1 Subscribe to all NDEF messages _subscribedMessageId = _device.SubscribeForMessage( "NDEF", MessageReceivedHandler); 2 Parse raw byte array in handler  http://www.nfc-forum.org/specs/ Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 18
  • 19. Reading NDEF // Convert the language code to a byte array Simple example: assembling payload of Text record 1 Subscribe to all NDEF messages= Encoding.UTF8; var languageEncoding var encodedLanguage = languageEncoding.GetBytes(languageCode); // Encode and convert the text to a byte array var encoding = (textEncoding == TextEncodingType.Utf8) ? Encoding.UTF8 : Encoding.BigEndianUnicode; var encodedText = encoding.GetBytes(text); // Calculate the length of the payload & create the array var payloadLength = 1 + encodedLanguage.Length + encodedText.Length; Payload = new byte[payloadLength]; _subscribedMessageId = _device.SubscribeForMessage( "NDEF", MessageReceivedHandler); 2 Parse raw byte array in handler  // Assemble the status byte Payload[0] = 0; // Make sure also the RFU bit is set to 0 // Text encoding if (textEncoding == TextEncodingType.Utf8) Payload[0] &= 0x7F; // ~0x80 else Payload[0] |= 0x80; http://www.nfc-forum.org/specs/ // Language code length Payload[0] |= (byte)(0x3f & (byte)encodedLanguage.Length); // Language code Array.Copy(encodedLanguage, 0, Payload, 1, encodedLanguage.Length); // Text Array.Copy(encodedText, 0, Payload, 1 + encodedLanguage.Length, encodedText.Length); Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 19
  • 20. Windows 8 & Windows Phone 8 NFC / NDEF LIBRARY FOR PROXIMITY APIS Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 20
  • 21. NDEF.codeplex.com Create NDEF messages & records (standard compliant) Reusable NDEF classes Parse information from raw byte arrays Fully documented Open Source LGPL license (based on Qt Mobility) Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 21
  • 22. NDEF Subscriptions 1 Subscribe to all NDEF formatted tags _subscribedMessageId = _device.SubscribeForMessage("NDEF", MessageReceivedHandler); 2 Parse NDEF message private void MessageReceivedHandler(ProximityDevice sender,  ProximityMessage message) { var msgArray = message.Data.ToArray(); NdefMessage ndefMessage = NdefMessage.FromByteArray(msgArray); [...] } Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 22
  • 23. NDEF Subscriptions 3 Analyze all contained NDEF records with specialized classes 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()); } } Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 23
  • 24. Write NDEF 1 Prepare & convert data // Initialize Smart Poster record with URI, Action + 1 Title var spRecord = new NdefSpRecord { Uri = "http://www.nfcinteractor.com" }; spRecord.AddTitle(new NdefTextRecord { Text = "Nfc Interactor", LanguageCode = "en" }); // Add record to NDEF message var msg = new NdefMessage { spRecord }; 2a Write tag // Publish NDEF message to a tag _device.PublishBinaryMessage("NDEF:WriteTag", msg.ToByteArray().AsBuffer()); 2b Publish to devices // Alternative: send NDEF message to another NFC device _device.PublishBinaryMessage("NDEF", msg.ToByteArray().AsBuffer()); Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 24
  • 25. APP LAUNCHING Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 25
  • 26. App Launch Scenarios Discover your app Share app to other users Create seamless multi-user experience Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 26
  • 27. App Launching Summary Register for Files URI protocol LaunchApp Tag Peer to Peer User opens particular file Tag launches app through custom URI scheme Tag directly contains app name and parameters App requests peer device to start the same app Not so relevant for NFC Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 27
  • 28. How to Launch Apps either or Win8 + WP8 Tag directly contains app name and custom data. No registration necessary. Custom URI scheme launches app. App needs to register. Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 28
  • 29. nearspeak: Good+morning. Protocol name Custom data Encoded Launch URI Examples* skype:mopius?call spotify:search:17th%20boulevard Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl * Definition & examples: http://en.wikipedia.org/wiki/URI_scheme 29
  • 30. User Experience No app installed 1 app installed 2+ apps installed Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 30
  • 31. WP Protocol Association Note: different in Win8 / WP8 1 Specify protocol name in WMAppManifest.xml ...</Tokens> Protocol <Extensions> name <Protocol Name="nearspeak" NavUriFragment="encodedLaunchUri=%s" TaskID="_default" /> Fixed </Extensions> Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 31
  • 32. WP Protocol Association Note: different in Win8 / WP8 2 Create UriMapper class to parse parameters class NearSpeakUriMapper : UriMapperBase { public override Uri MapUri(Uri uri) { // Example: "Protocol?encodedLaunchUri=nearspeak:Good+morning." var tempUri = HttpUtility.UrlDecode(uri.ToString()); var launchContents = Regex.Match(tempUri, @"nearspeak:(.*)$").Groups[1].Value; if (!String.IsNullOrEmpty(launchContents)) { // Launched from associated "nearspeak:" protocol // Call MainPage.xaml with parameters return new Uri("/MainPage.xaml?ms_nfp_launchargs=" + launchContents, UriKind.Relative); } // Include the original URI with the mapping to the main page return uri; }} Argument already handled in step 9 of LaunchApp tags (MainPage.OnNavigatedTo) Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 32
  • 33. WP Protocol Association 3 Use UriMapper in App.xaml.cs (region: ) private void InitializePhoneApplication() { RootFrame = new PhoneApplicationFrame(); RootFrame.UriMapper = new NearSpeakUriMapper(); } – If needed: launch protocol from app (for app2app comm) await Windows.System.Launcher.LaunchUriAsync( new Uri("nearspeak:Good+morning.")); Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 33
  • 34. bit.ly/AppLaunching Windows 8 Protocol Association Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 34
  • 35. parameters platform 1 app name 1 platform 2 app name 2 … Encoded into NDEF message* Directly launch App Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl * For your low-level interest: type: Absolute URI, type name format: windows.com/LaunchApp. Contents re-formatted, e.g., with string lengths before each value 35
  • 36. Write LaunchApp Tags Note: different in Win8 / WP8 1 Launch parameters, platforms + app IDs (note: Win8/WP8 ID format differences) var launchArgs = "user=default";   // Can be empty // The app's product id from the app manifest, wrapped in {} var productId = "{xxx}";  var launchAppMessage = launchArgs + "tWindowsPhonet" + productId; 2 Convert to byte array var dataWriter = new Windows.Storage.Streams.DataWriter {UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf16LE};    dataWriter.WriteString(launchAppMessage);  3 Write to tags _device.PublishBinaryMessage("LaunchApp:WriteTag", dataWriter.DetachBuffer()); Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 36
  • 37. PEER TO PEER Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 37
  • 38. Seamless MultiUser Games & Collaboration Tap for Quick Data Exchange Long Term Connection ProximityDevice PeerFinder Exchange Windows / NDEF messages, SNEP protocol Automatically builds Bt / WiFi Direct socket connection Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 38
  • 39. Establishing Trigger Long Term Connection Browse Interact with Tap Start Search NFC Bt, WiFi, etc. Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 39
  • 40. Tap to Trigger App not installed App installed Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 40
  • 41. Connection State Proximity gesture complete Devices can be pulled away Which device initiated tap gesture? → Connecting, other device Listening 1 PeerFound 2 Connecting / Listening Access socket of persistent transport (e.g., TCP/IP, Bt) 3 Completed Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 41
  • 42. Find Peers 1 Start waiting for triggered connections PeerFinder.TriggeredConnectionStateChanged += TriggeredConnectionStateChanged; PeerFinder.Start(); 2 Peer found & connection established? Send message over socket private async void TriggeredConnectionStateChanged(object sender,  TriggeredConnectionStateChangedEventArgs eventArgs) { if (eventArgs.State == TriggeredConnectState.Completed) { // Socket connection established! var dataWriter = new DataWriter(eventArgs.Socket.OutputStream); dataWriter.WriteString("Hello Peer!"); var numBytesWritten = await dataWriter.StoreAsync(); 3 }} Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl * For URI records + simple Smart Poster (w/o title), use the WindowsUri type. 42 Completed
  • 43. UX Recommendations* User initiated peer search only Ask for consent Show connection state Failed connection? Inform & revert to single-user mode Let user get out of proximity experience Proximity: only if connection details not relevant Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl * bit.ly/ProximityUX 43
  • 44. NFC Tools Proximity Tapper for WP emulator – http://proximitytapper.codeplex.com/ Open NFC Simulator – http://open-nfc.org/wp/editions/android/ NFC plugin for Eclipse: NDEF Editor – https://code.google.com/p/nfc-eclipse-plugin/ Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 44
  • 45. nfcinteractor.com Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 45
  • 46. NFC Resources  NFC News: nfcworld.com  NFC developer comparison (WP, Android, BlackBerry): bit.ly/NfcDevCompare  Specifications: nfc-forum.org Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 46
  • 47. Thank You. Andreas Jakl @mopius mopius.com nfcinteractor.com Windows 8 Platform NFC Development v2.0.0 © 2014 Andreas Jakl 47