Social Applications on Android using NFC and Junction

NFC Brings our Devices Together

Recently, many of us in the Stanford MobiSocial lab have grown very excited about the prospect of having NFC in smartphones. NFC, or near-field communication, allows two devices to interact simply by bringing them close together. NFC readers read in data called “tags”, which are a collection of records with well-defined formats. Records can be urls, business cards, or other domain-specific data type.

It appears that NFC may become standard in the next generation of smartphones, largely driven by the promise of mobile payments, a new revenue stream for companies in the mobile space. Beyond payments, other promising applications of NFC include ticketing for events and transportation, contact information exchange, quickly looking up product information, and more.

NFC supports different modes of operation– a reader (such as a smartphone) can scan a tag to pull data from it. These tags are cheap and small, and can be stuck just about anywhere, providing a digital identity for some thing or some place. NFC also supports P2P transactions, allowing two devices to pass data back and forth. With NFC available on future smartphones, this opens up exciting new possibilities.

NFC on Google’s Nexus S

When Google and Samsung announced the Nexus S, it marked the first time that NFC would appear on an Android phone. However, it was revealed that support for NFC would be limited to simply reading tags in the Gingerbread release. Not many people have NFC tags yet, so this was a bit of a let-down. But it was discovered that the limitations were purely in software, and so we anxiously awaited news of further development of the NFC stack.

That was, until we were fortunate enough to get our hands on a pair of Nexus S phones to play with. We were inspired to look into the state of NFC on Android a bit more in depth to see if it’d be possible to push our own P2P applications.

As it turns out, P2P mode wasn’t completely ignored in the Gingerbread cycle. After looking through some of the commits for Gingerbread (long live open source!), we found an initial implementation of P2P in Android. And, with a bit of work, we were able to run P2P mode successfully between our two devices.

The initial implementation was called MyTag, and allowed a phone to present an NFC tag to another phone. Note that although NFC has a mode for “card emulation”, this implementation uses a true P2P connection to send a tag between phones, with a socket established between the MyTagServer and MyTagClient.

Most of our changes for enabling P2P mode were in the Nfc package. And since this package is a bundled part of Gingerbread, the applications we built using P2P mode require a custom version of the Android OS. So our applications remain proof-of-concepts for now.

Using NFC and Junction

We have written a few basic demonstrations of NFC in Android. We use our own custom NFC api to achieve them, and can only hope that Android’s api will eventually allow these types of interactions in the near future. Running these demonstrations currently requires a custom build of the Android OS. We also make use of the Junction platform (discussed below), which allows an application to be run across phones, even if a joining phone doesn’t yet have the application being used.

Our first demonstration shows how a file can be transferred between two phones, here a photo from the Gallery application. We modified the built-in Gallery application to allow a picture to be shared simply by opening it on one phone and touching it to another. The receiver is then prompted to download the file.

Note that in our implementation, the actual file is transferred between phones over HTTP. We simply use NFC to share a URL representing the image. NFC is not the speediest transfer protocol and requires the devices to remain in contact for the duration of the transfer, so we simply use it to kick off our transfer.

YouTube Preview Image

Our next demonstration is of a shared application– a collaborative whiteboard. Again, we use NFC to simply transfer a URL and Junction does the rest. The URL contains enough information to tell the joining device (a) which application is being used, and (b) which application session to join. Junction also tells joining parties where the software can be found if it’s not yet available on the device.

Note that Junction applications are truly multiparty, and we could join even more phones by simply touching an interested party to any device that’s already in the session.

YouTube Preview Image

Junction and Device-Spanning Applications

We’ve been working on a platform called Junction, with the goal of making device-spanning applications easy to write and easy to use. We’ve written games like poker that work across phones and TVs, secure authentication between a desktop browser and a phone, and the whiteboard application shown above, which can be run across an array of devices including PCs, tablets, and phones.

A key challenge in making these applications usable is having applications discover each other across devices. We quickly learned that there’s no silver bullet to accomplish this; Network discover such as SSDP (used in UPnP) work well when the applications are on the same network, but don’t support web applications or phones with 3G connections. QR codes can be used when connecting a device with a screen to another device with a camera. Bluetooth beaconing works well for devices in proximity, when the devices all have programmable access to Bluetooth.

Because Junction has a focus on mobile platforms (with support for Android and iPhone/iPad), we’ve been excited about NFC. NFC potentially allows a device to share its context without interrupting the user experience. The whiteboard is still running in full-screen while being shared with another phone.

Junction applications share just enough information to identify the application being run, and identify the application session to join. Junction also supports a process by which an application can be downloaded if it is not yet available on the participant’s platform.

Junction and NFC complement each other well for launching applications across devices. NFC provides the bootstrapping necessary to start the application, and Junction allows the application to run across devices. As we said, we have no knowledge of what the future of NFC apis will look like in smartphones, but hope that these types of interactions will be possible. But you can start building Junction applications now.

Jan25

20 Responses to “Social Applications on Android using NFC and Junction”

  1. NFC, like Wireless Direct, has useful P2P networking properties. But there still needs to be a service discovery layer to find and discover available Junction switchboards, that’s the problem hinted at towards the end, no?

    mDNS/DNS-SD is a common low level model. It looks like Junction is just a particular XMPP chat room– why not just tag the MUC service with a new “switchboard” feature in the disco query, and use conventional Avahi to discover the server?

    For more web-ful greenfield solutions, Paul Kinlan wrote a web based service discovery system modeled loosely on Intent’s in Android. There seems to be some conceptual parity with Junction’s intents.

    There’s some overlap among the different realms of service discovery. There can be multiple switchboards, each offering multiple ongoing Activities. Presenting that complexity in a manageable form is a great challenge. XMPP has a lot to build off here; if there were clients better at managing multiple arrays of services (rather than just being simple IM clients) I’d suggest piggybacking off their efforts. Also note XMPP has quite the number of addons for MUC. XEP-0289 for instance talks about Federated MUC’s, by way of which I for instance might be capable of hosting my own proxy of your Poker activity.

    Thanks for writing this. I’ve been interested in multi-user applications since a video wall project I did back in 2000, and this article clued me in to one of the most interesting efforts I’ve seen in the intervening decade. Great work, really.

  2. pardon, i meant to call out Wi-Fi Direct as a P2P enabler. “Wireless Direct” was a mistake.

  3. Hi rektide,

    Thanks for the insights. You are right that we aren’t solving how to find the switchboard here– NFC gives us something else, which is once a phone is already running an activity that’s multi-party-ready, another party can join easily.

    For the first phone, how it finds a switchboard is still a hard problem. Like you said, mDNS is a great solution, but only for finding services on a LAN.

    We’ve also been playing with different technologies for hosting activities– XMPP was the first, but we’ve also run activities over Bluetooth and on a LAN using simple socket server implementations. Different apps might want to use different technologies for various reasons. The first step, though, is to isolate the writing of the apps from the underlying messaging layer, and then to represent the session with a universal URI, regardless of what method is chosen.

  4. [...]  |  MobiSocial News  | Email this | Comments Engadget Tweet This Post [...]

  5. But I hve this application on my iPhone called Bump that does the same thing. A couple years ago now

    • Warren, I think the point here is why give out information about who & what you share with to a big-brother for-profit company, such as Bump, FB or Google? What you do and who you do it with should be your bloody own business, and it should stay that way instead of a company perving on you.

  6. [...] MobiSocial Posted in News Tags: Android, Bluetooth, NFC « LTE und WiMAX kommen zusammen – Dual [...]

  7. What does “a custom version of the Android OS” mean? Is is possible that we implement the same program with our own mobile phones of Google’s Nexus S?

    • Ben Dodson Says:
      March 7, 2011 at 4:23 pm

      As of Android 2.3.3, all of the applications we wrote about are now possible without a custom Android build.

  8. [...] will enable a host of new applications for smartphones, but it will be a few years before the technology becomes ubiquitous. But that [...]

  9. Ok Ok this is all getting a little to freaky, soon they will want to put devices in your head to get each others knowledge.
    Apart that outburst I think it has a lot of capabilities and uses in the business and schooling areas, as long as its safe when transmitting information.

  10. Nice apps. Thank u.

  11. [...] few weeks ago, we demonstrated a few social applications running between two Android phones, using NFC and Junction to make the [...]

  12. I’m new to NFC. I’m thinking a project to create a mimic a simple transit system. In this project, I will have devices like gates and ticketing machine that has NFC readers on them. These NFC readers will be reading and writing data (Card purse value, station ID, etc) onto a andorid NFC phone. Thus I think I need the NFC phone to
    – be configured in Card Emulation Mode
    – to emulate an RFID card like Mifare Ultralight or Sony Felica
    May i know what I need to do to configure to card Emulation Mode?
    What phone should I choose that already support mifare Ultralight or Sony Felica without further coding. If not, do I need to learn how to code these card OS into the secure element of the phone and how I could do that?
    Do I need to define how the Info is stored in the “card” on the NFC phone and how do I do that.
    Do I need to be concerned about security keys to read and write on the “card” on the NFC phone?
    Hope I could get your advice.
    Thanks

  13. Ben Dodson Says:
    January 17, 2012 at 11:01 am

    Hi Roy,

    Android doesn’t support card emulation, however I think blackberry does. This post might have more helpful information for you:

    http://mobisocial.stanford.edu/news/2011/12/building-nfc-aware-applications/

  14. Another great feature from the android. I’m not that very familiar with OS and stuff but I am very grateful they do exist. Posts like this reminds me about the fact how vast technology is and how fast it is evolving

  15. What android os version is needed? what does custom android build mean?
    is it compatible with android 2.2 version and above?

  16. innehåller Thuja occidentalis…

    [...]d Great job here. I definitely enjoyed what you had to say. Keep heading beca bs[...]…

  17. I am really impressed together with your writing skills and also with the
    format for your weblog. Is that this a paid topic or
    did you customize it yourself? Anyway keep up the excellent high quality writing, it
    is uncommon to see a nice blog like this one nowadays.

Leave a Reply