Use the PeerFinder API to launch applications via NFC

With the introduction of NFC on Windows Phone 8, the scenarios of device interaction become much more reachable to consumers and developers. By simply by tapping one WP8 device with another, we can perform a variety of tasks, like sharing a contact, photo, video, or app, pairing with Bluetooth, etc.

The Proximity API in WP8 provides two main classes for NFC related features: ProximityDevice and PeerFinder. ProximityDevice enables functionality like publish/subscribe for NFC messages to and from tags or another devices, while PeerFinder focuses on pairing two devices with a socket connection using NFC tapping or browsing without NFC involvement.

Launching an application from another device is one of the most important features that NFC provides. In most cases, launching the same application from another device is desired to enable further interactions on the same app context between two devices, such as multi-player games, messaging apps, media sharing, etc. Both ProximityDevice and PeerFinder can perform this task.

By using ProximityDevice, developers need to make a URI association for the app and then publish the custom URI to another device. This approach enables the app to interact with other applications as well. However, sometimes app developers do not want to disclose the interface to others due to confidentiality. In such cases, the URI association might not be the best option.

On the other hand, many developers have encountered issues where if both apps are running in the foreground on separate devices and either Fast App Resume (FAR) or BackgroundExecution is defined in the manifest, then passing the URI through NFC will not trigger the MapUri function to launch the desired page in the application. In such cases, the PeerFinder approach to launch the same app on another device becomes more reliable option for developers.

So, how do you launch the same app on another device using PeerFinder? The solution is pretty simple. Developers just need to include the following code in their application. As it requires NFC to make tapping gesture work, the application needs to have ID_CAP_PROXIMITY and ID_REQ_NFC defined in the manifest.

...
PeerFinder.TriggeredConnectionStateChanged += PeerFinder_TriggeredConnectionStateChanged;
PeerFinder.Start();
...
void PeerFinder_TriggeredConnectionStateChanged(object sender, TriggeredConnectionStateChangedEventArgs args)
{
//to-do
}

After PeerFinder is started on device A, then when another device (“B”) enters into proximity range, device B will behave according to the following rules:

  • Case 1: If device A has the app but device B doesn’t, device B will get a prompt to search for the app in the store as in the first illustration.
  • Case 2: If both device A and B have the app installed and the app is not yet launched on B, then B will get a prompt to launch the app as in the second illustration.
  • Case 3: If both device A and B have the app installed and both have launched the same app, then TriggeredConnectionStateChanged will get notified and further actions can be performed.

App not installed    App not installed and not launched

If the app needs a socket connection for further action between two devices, then it can check the TriggeredConnectState property in the  TriggeredConnectionStateChangedEventArgs passed in with the  TriggeredConnectionStateChanged event. Once the state is changed to TriggeredConnectState.completed, then the Socket property under TriggeredConnectionStateChangedEventArgs will be ready to use.

Some developers want to distinguish between normal application launching and launching by PeerFinder. This can be achieved by using the URI mapper and checking the URI passed. In the PeerFinder case, the URI passed to the MapUri function will look like this:

/MainPage.xaml?ms_nfp_launchargs=Windows.Networking.Proximity.PeerFinder:StreamSocket

Launching the same app on another device using PeerFinder does not require URI association, which implies that no other application can pretend to be the application by associating the same URI theme. This ensures that only the expected app is launched. It also resolves the issue mentioned above in the FAR or BackgroundExecution case. However, if developers want to share their application experiences with other applications, then using ProximityDevice with URI association is the proper option to choose.

How to use emulators to develop NFC features on WP8

One of the more interesting features of Windows Phone 8 is its Proximity Framework for Near-field communications (NFC). Both Nokia and Microsoft have heavily invested in this area. The Proximity API provides you the controls needed to innovate on NFC technology, but at the moment Windows Phone SDK default emulator does not simulate NFC. That means you have to use real WP8 devices to test and debug NFC-related features. If you’re developing a feature to be used between NFC-enabled devices, you’ll need to have at least two devices in hand. In addition, there are often physical movements required to perform NFC interactions while debugging.

Continue reading

Nfc Interactor + NDEF Library for Windows Phone 8

As one of the world’s first Windows Phone 8 applications, Nfc Interactor is now available for download in the Windows Phone Store.

This is an incredibly useful tool for developers, as it allows you to experiment with NFC on your phone, without the need to write your own code right away.

Nfc Tool for Developers

Nfc Interactor can read and parse NFC tag contents. Even better is that you can use it to easily create and write your own tags. This allows you to for example test how your WP8 app reacts to LaunchApp tags, or if it works to launch your app through your own custom URI scheme, probably even with parameters that are written to the tag. More details in my article: How to Launch Apps via Proximity APIs (NFC).

Nfc Interactor also supports peer-to-peer communication for sending messages to another device (using the standardized SNEP protocol). As you can define any kind of NDEF message in the editor, you can test how the other phone will react to incoming messages; or – in case your app is listening to incoming proximity messages – you can test how your app will react; both to planned messages, as well as if your app stays stable if it receives unexpected messages via NFC.

Open Source Nfc Code for Developers

In some scenarios, you will need to have more control over the actual NFC message contents than the Windows Proximity APIs will provide to you. Reading, understanding and implementing the complex NDEF message specifications of the NFC Forum will cost you many hours or even days of precious work time.

To make your life easier and get your new NFC apps quicker to the market, I’ve released the heart of Nfc Interactor as an open source component: the NDEF Library for Proximity APIs.

The library is collection of C# classes that works both for Windows 8 as well as for Windows Phone 8 apps. You can use it to create NDEF messages containing one or more NDEF records, as well as for reading and parsing messages you got from peers or a tag.

Using the library will for example enable you to write a cross-platform LaunchApp tag, which contains multiple records: a Windows LaunchApp record for Windows (Phone) 8, a cutom record type (external RTD) for Symbian, plus an Android Application Record for Google Android. I’ve published more details about how to get this to work at the Microsoft TechNet Wiki.

Getting Started

With NFC now being an important part of both Windows Phone 8 as well as Windows 8, you can write exciting new apps, as well as integrate NFC into your existing apps to expand your customer base or to add unique new features.

The article How to Acquire and Publish Content from / to NFC Tags and Proximity Peers contains a short and concise overview of the Proximity APIs and how to put them into use.

NFC on the Windows 8 Platform

The Proximity APIs enable you to create NFC apps for the Windows 8 platform. Designed to be easy to use and streamlined for the most common use cases, the APIs allow integrating powerful features into your apps in a very short time.

At the NFC Congress in Hagenberg, Austria, we’ve just presented the first overview of those APIs during our Developer Workshop that was opening the conference.

Windows 8 Platform NFC Development Slides

To get an overview of the new Proximity APIs, the technical presentation will introduce you to possible use cases along with a few code snippets that will help you with getting started.

The slightly shortened version of the technical part of the session from the congress is now online for your viewing and downloading pleasure at Slideshare and includes the following contents:

  • Subscribe to proximity messages
  • Publish messages to peers and tags (WindowsUri and NDEF records)
  • Parse & create NDEF messages (including Smart Posters)
  • Launching apps on own and peer devices
  • Registering for custom URI schemes and protocols
  • LaunchApp tags to directly start the app
  • Peer to peer: quick data exchange and long term connections with Wi-Fi Direct / Bluetooth
  • Establishing peer to peer socket communications simply by tapping two devices
  • User Experience recommendations for peer to peer apps

NDEF Library for Proximity APIs

The Proximity APIs make it easy to work with URIs, but lack ready made classes for directly handling NDEF records and messages. The NDEF Library for Proximity APIs extends the framework in those areas and allows you to create standard compliant NDEF tags, as well as reading and parsing data out of the raw byte arrays you get from Proximity APIs.

Currently, the library supports Smart Posters, URI and Text records – with more record types planned to be added in the future. The classes are released under open source license (LGPL, as they’re based on the Qt Mobility Connectivity module), allowing you to directly integrate them into your own project.

Instead of having to read through pages of technical specs and handling the bits and bytes of the records manually, it’ll only take you a minute to integrate the library into your project and start working with NDEF records.

You can download the library at ndef.codeplex.com and get more information at nfcinteractor.com.

Nfc Interactor for Windows Phone 8

Also at the conference, I’ve announced that Nfc Interactor will be available for Windows Phone 8!

The powerful app is currently available for Symbian and the Nokia N9 and allows you to analyze low level information about NFC tag contents, as well as writing your own tags with a flexible and dynamic composer interface.

The first live demo was shown at the conference, more information will be available online in the near future at nfcinteractor.com!

New Features in Nfc Interactor 4.0

Nfc Interactor 4.0 is now available as download or update in the Nokia Store. It’s a big step forward and a major evolution from the previously published version 2.0. Many new features will allow you to read and write NFC tags even more comfortably, as well as push your NDEF creations directly to other NFC phones.

New features for peer to peer

  • Send NDEF messages through the standardized SNEP (Simple NDEF Exchange Protocol) to other NFC devices, including Windows 8 devices, the Nokia Lumia 610 NFC or recent Android phones (Ice Cream Sandwich+)
  • Send raw NDEF messages through a direct LLCP (Logical Link Control Protocol) socket
    • Connection-oriented or connection-less connection
    • Select service name or port for the connection
    • Connect client- and/or server-socket for connection-oriented
  • Receive SNEP messages and parse their contents + protocol information (Symbian only)

New features for tag reading / writing

  • Long-press on a read tag to directly clone a tag you have read
  • Long-press on a read tag to edit a tag you have read
  • Save composed tags for later re-use
  • Load previously saved tag compositions or tags collected from the field into the editor to change the contents or write the tag again
  • Extracts and stores images included in the tag on the phone file system
  • Select the data directory for storing tags, also allowing you to copy the raw NDEF message data to your PC for further analysis
  • New settings screen to configure saving and peer-to-peer behavior
  • Automatically format factory empty tags (-> writes empty message before writing the real contents)
  • Foursquare support added to social message template

Source Code & Download

These additions extend the full feature list, which is now already fills several pages. As usual, the full source code is released under the Nokia Example Code License and can be downloaded for free from the SVN server. The new version also demonstrates the use of the brand new Simple NDEF Exchange Push library for the Nokia N9, which allows sending SNEP messages from MeeGo applications. You need to add it to your Qt SDK to compile Nfc Interactor for MeeGo Harmattan on your local machine.

If you’d rather like to just use the app instead of digging into the source code, you can conveniently download the app from the Nokia Store. You can either go for the free, ad-supported version, or upgrade to Unlimited, which doesn’t show ads and allows writing / pushing an unlimited number of advanced messages.

Nokia Lumia 610 – with NFC

At WIMA 2012 in Monaco, Nokia announced a new NFC smartphone. The Nokia Lumia 610 NFC.

The device is Nokia’s 1st Windows Phone NFC enabled smartphone.

Using the Lumia 610 as a reference product design, Nokia in cooperation with partners added the NFC support. The device, just like its predecessor, is powered by Windows Phone 7.5 operating system. For general detailed specifications on the Lumia 610 please visit our device specification section. Further I will concentrate on general overview of the "NFC" part of the Lumia 610 NFC.

NFC support

Nokia worked together with INSIDE Secure, a company well known in the NFC industry for providing leading NFC solutions, to integrate NFC hardware and software support on top of the already established Lumia 610 product. 

Supporting Operating Modes

  • Peer-2-peer

The device supports peer-2-peer exchange over the NFC radio. The supported protocols are SNEP (Simple NDEF Exchange Protocol) and the lower level LLCP (Logical Link Control Protocol)

  • Reader/writer

The device is able to read and write to a number of NFC tags. Supported technologies are NFC forum Type 1,2,3,4 (Including Topaz, Ultralight C, NTag, Felica, DesFire, ISO-14443 Type A/B, ..), Mifare Std, Kovio and others

  • Virtual Tag

The device is able to simulate an NDEF Type 4 Tag

  • Card Emulation

The device is able to emulate a SmartCard, with data exchange with a SIM based card application over SWP (Single Wire Protocol) supporting payment and ticketing use cases (Secure NFC

MasterCard PayPass® and Visa payWave® certified   

The Nokia Lumia 610 NFC passed Mastercard and Visa contactless payment certification.

Availability

The Nokia Lumia 610 NFC is initially planned to be available with Orange later this year. Other markets and operators availablity has not been announced yet.

APIs and functionalities

The above mentioned functionalities are exposed via the InsideSecure’s Open-NFC platform. It includes APIs to access the whole NFC functionality enabling creation of a variety of NFC application use cases. InsideSecure made a port of the Open NFC platform to Microsoft Platforms. Visit the Open NFC platform pages for more details. 

3rd party application development

To develop NFC applications for the Lumia 610 NFC developers need the standard Windows Phone development environment  plus:

  • Open NFC for WP libraries
  • Nokia Lumia 610 NFC device with custom firmware 

At the moment the Open NFC WP7 port/addon is not publicly available.

Partners of Nokia (including Nokia Developer PRO and Launchpad program members) are invited to contact their Nokia contact person or send a query to nokia.developer.PRO@nokia.com for detailed information and requirements.

Distribution of NFC enabled apps in Microsoft Marketplace

In order to be offered for the Lumia 610 NFC, 3rd party apps must be signed by either Nokia or a mobile operator. This will enable them to be published in Windows Phone Marketplace. The application developers must also ensure that the application will install and work also on non-NFC enabled Windows Phone phones, i.e. by disabling the NFC features of the application to the user

More info to follow!

Payment and ticketing with Nokia 603 and 808 PureView

Nokia 603 with Symbian Belle Feature Pack 1 and Nokia 808 Pureview are ready for implementing Payment and Ticketing solutions! In this post I will go into the details on Secure NFC implementation and how developers can get started in development of secure NFC applications on Nokia Symbian devices.

Support for SIM based NFC architecture using SWP protocol

Secure storage and provisioning of sensitive information (i.e. Credit Card details, values, PINs etc) needed to perform secure transactions with mobile devices is handled by the UICC/SIM card. Nokia HW/SW provides a channel for both external NFC infrastructure (POS readers, transit terminals, OTA provisioning) as well as on-device UI applications (wallets) to be able to securely exchange data over SWP protocol with the secure applications stored (and managed) on the SIM card.

Card Emulation mode

The Symbian NFC component has now added support for Card Emulation mode and it works interchangeably to peer-2-peer mode and reader mode when NFC radio is active. In card emulation mode all communication with the NFC radio is routed directly to the SIM card via the SWP protocol. The communication is usually in the form of ADPU packets follwoing the ISO 14443 standard (Smart Cards)

Typical architecture

In a typical use case the MNO will issue to the customer a UICC enabled SIM card. Additionally it could offer the customer a contactless payment or ticketing service (in partnership with a local Bank, loyalty or transportation service).

Subject to service agreement with the customer, the operator or service provider will issue the related payment or transportation cardlet to the user’s SIM card using a provisioning service provider or TSM (Trusted Service Manager). TSM’s role is to manage the secure provisioning & management of payment and ticketing services to end users. Usually this provisioning is done using OTA (Over-the-air) deployment (using BIP – bearer independent protocol).

The provisioning of these services may also include a dedicated Wallet application that is installed on the customers device which can then manage all (or some) the cards stored on the customer’s SIM card and is actually what the customer sees and uses to perform transactions with contactless/NFC infrastructure.

Low Battery mode

In payment and ticketing use cases it is important to offer customers NFC/contactless services in cases when the phone battery runs out (i.e. to be able to use transportation or to pay for services). To satisfy requirements Nokia has implemented an operator variant customizable Low Battery mode which will enable to make a few transactions with the card emulation mode in cases where the device will shut down due to low battery.

Devices supporting Card Emulation

Nokia 603 with Symbian Belle Feature Pack 1 and Nokia 808 Pureview

Note: at the time of writing the Nokia 603 has received MasterCard Paypass certification

Development environment:

Development of Card Emulation solutions differs a bit from regular mobile application development as it requires more infrastructure capabilities. One might say that the wallet development is the easy part, the more challenging part is to have the right e-2-e infrastructure. Usually the solutions on mobile devices have 2 parts,

- the Wallet UI application (managing user’s cards and for listening, preparing cards for transactions). For the Wallet UI application the Development environment is Java ME

- the "card" applications (cardlets, applets) running on the SIM card. For the "Card" applications the development environment depends on the SIM manufacturer (usually JavaCard technology)

Recommended Development Setup 

Related APIs 

The Contactless Communications API defines support to exchaning information between contactless targets

The Security and Trust Services API for J2ME defines support for smart card communication, generation of digital signatures, and low-level cryptography operations.

Nokia extensions to the JSR257 API

  • FakePower off API

API for receiving notifications about the low battery mode state (i.e. to alert the user) 

  • Branding API

API for registering post transaction events. (i.e. play video, show bitmap, launch application)

Examples

Nokia made available an example application demonstrating a typical wallet application supporting contactless transactions using all the necessary APIs and available as source code. (The project is available to Nokia Developer Launchpad/PRO members only)

Avaliability 

The mentioned enablers for building NFC enabled payment & ticketing solutions on Nokia Symbian devices are available to Nokia Developer Launchpad and PRO members only.

Cross Platform NFC Geo Tags

Nfc Geo Tag on the Nokia N9.Imagine the following: you’re playing a treasure hunt game in your home town. At one station, you touch an NFC tag with your Nokia phone; this opens Nokia Maps to reveal the location of the final place where to collect the treasure. Similar scenarios are possible if you’d like to use Nokia Maps to navigate to the point of interest that you just read about; for example, the St. Stephen’s Cathedral in Vienna, after reading about it in a tourist brochure.

Alternatives

To implement this, you need to store the longitude and latitude of the landmark on the NFC tag (you could also call them "GPS coordinates"). But how to store them? This use case hasn’t been set by the current NDEF URI RTD specification of the NFC Forum, so there isn’t necessarily a solution that works across all NFC enabled phones.

One approach is using the geo: URI scheme (RFC 5870). In the most simple and short form (important due to the limited space on a tag), the URI to write to the tag could look like the following: "geo:60.17,24.829". This encodes the decimal coordinates with latitude of 60.17 and longitude 24.829 in WSG-84 (the location of the Nokia House in Finland, by the way). This works fine with the N9 and directly opens the Nokia Maps client showing the correct location, given that you have PR 1.1+, which is required for default NFC tag handling by the phone. However, Symbian currently can’t understand Geo URIs.

An alternative is to write the URL to Nokia Maps to the tag, according to the Nokia Maps Rendering API. For example: http://m.ovi.me/?c=60.17,24.829. When opening this URL on a Symbian phone, it automatically opens the Nokia Maps client at the correct location. On other devices like the PC, it redirects to the full Nokia Maps web client or the HTML5 version of it. However, MeeGo Harmattan just shows the static map image and doesn’t start the Nokia Maps client.

Cross Platform Geo Tags

So, those two approaches don’t work across the Nokia portfolio. However, there is a simple solution: store the URI of a small script on a server, which then redirects a MeeGo (or Android) phone to the Geo URI, and every other device to the Nokia Maps URI. You can retrieve the operating system by checking the user agent of the browser.

On MeeGo, you can directly send out an HTML header to redirect the browser to the Geo URI (causing it to open Nokia Maps), without loading and rendering the actual web page. On Symbian, a JavaScript redirect can put the browser on the right track and trigger it to open the Nokia Maps client.

Creating Nfc Geo Tags

To make this easier for you, the new Nfc Interactor app (available for Symbian and the Nokia N9) lets you conveniently write geo tags by just entering the coordinates. In the tag compose view, you can also choose which of the three variants you want to write to the Nfc tag. The app will take care of formatting the actual NDEF message for the tag.

For your experiments, the maps redirection PHP script explained above is hosted on http://nfcinteractor.com/m.php and can be used with a URI on the NFC tag like this:

http://nfcinteractor.com/m?c=60.17,24.829

Note that there is no service or uptime guarantee for the hosted script at nfcinteractor.com – it’s intended for testing purposes only and could be removed at any point. You should host the script on your own server for real-world deployment. See the web services information page for more details.

Additionally, hosting the service on your own web server allows you
to add custom-named places to the script, so that the link on the tag
doesn’t need to contain the coordinates, but you can link to a custom
place-name instead. See the source code of the script for details on how
you can add your own places. Example:

http://nfcinteractor.com/m?l=nokia

The source code of the Geo Tags redirection script is now also available under the open source BSD license, so that you can adapt it to your needs, add custom locations (instead of specifying the coordinates as parameters) and upload the script to your own web server.

Example application showcasing key Harmattan APIs

We have published a new example application for Harmattan developers.

The application’s source code is available on harmattan-dev. It can be built in Qt SDK using the enclosed project-file.

The application features several key elements in the Harmattan application programming interface, and thus provides a good starting point for learning about specific technologies and application development for N9 in general.

The initial version of the showcase application concentrates on Qt Mobility interfaces (ranging from maps, multimedia and messaging to visualizing the sensor data with a compass overlaid on camera input).

In the messaging area it provides insight how NFC is easily integrated into an application.

Feedback on the application are best given as comments in this blog entry.

N9 showing the compass in the showcase application.