31

I am looking for a way to create a NFC-tag that shares the wifi credentials of my network without my guests having to have any special NFC apps on their phone (other than whats coming with the phone). I have been looking at apps and services like NFC Tag Writer, WifiTap, NFC Task Launcher and NFCLabels.com, but it seems to me like it I would need to have the apps on the guest mobile as well to be able to use it, but I am not able to test it as I only have one NFC-enabled phone available. (Yes, I know, twisting my brains for nothing, but heck, weird behaviour is nothing new...)

My closest clue is that WifiTap states that:

The app processes URIs in the format of wifi://[network ssid]/[wep|wpa|open]/[network key]

If this is actually universal this would mean that I could do what I what I want to, but I have not found any confirmation on this. So, how could what I want be done and am I on the right track with the clue from WifiTap?

Christian L
  • 357
  • 1
  • 4
  • 5

5 Answers5

22

As Alex wrote in a comment, you can now (since Lollipop) write a tag containing Wi-Fi credentials directly from the Android Wi-Fi settings: long-tap a network → Write to NFC tag.

It seems to be an NDEF-formatted tag with the application/vnd.wfa.wsc MIME type and a "WPS NFC" token.

The relevant source code can be found in platform/packages/apps/Settings/src/com/android/settings/wifi/WriteWifiConfigToNfcDialog.java.

Bruno Parmentier
  • 1,219
  • 2
  • 14
  • 34
  • 1
    If you're trying to long tap a network to write to NFC tag, remember to turn NFC on. – Rui Santos Feb 11 '16 at 21:41
  • Following this question, I wrote an app that writes Wi-Fi credentials to NFC tags using the same format as Android: https://github.com/bparmentier/WiFiKeyShare – Bruno Parmentier Feb 19 '19 at 15:43
11

There is an official standard for this kind of situation: NFC Forum Connection Handover Technical Specification. However, this is currently not supported by Android. I don't think there is currently any way to transfer WiFi credentials using NFC without the help of a dedicated app.

One way of going about this is to create (or find) an app in the Google Play Store that has the following properties:

  1. Intent filter for ACTION_NDEF_DISCOVERED and as URI the URL of the app in the Play Store.
  2. Intent filter for ACTION_NDEF_DISCOVERED and as type some proprietary type (e.g. a MIME type)

Then you can create tags with an NDEF message containing the following NDEF records:

  1. SmartPoster record with Play Store URI and some descriptive text (e.g. name of the app)
  2. Record of proprietary type containing the WiFi credentials
  3. Android Application Record for the app

The 3rd record will make sure that the proper app will always be started or the device user will be redirected to the Play Store to install it. This works only on ICS, however, but the 1st record (combined with the 1st intent filter) serves the same purpose on Gingerbread.

NFC guy
  • 10,151
  • 3
  • 27
  • 58
  • Isn't the connection handover spec meant for short-term peer-to-peer connections? My understanding is that its purpose is to facilitate transmission of longer messages than is practical over NFC alone, not to serve as a general-purpose network configuration protocol. I'd expect Android to implement this, and in fact it does--see http://androidxref.com/4.1.1/xref/packages/apps/Nfc/src/com/android/nfc/handover/HandoverManager.java. – Ian Ni-Lewis Oct 29 '12 at 01:54
  • @IanNi-Lewis The spec is not very clear on that point, I would say. See, for example, the introduction in section 2.1: it does not mention the length of time that the resulting connection lasts. However, I was specifically thinking of the "Static Handover" case (section 2.3), where the Handover Selector is not an NFC Forum Device and instead a tag is used to set up a (non-NFC) connection. In the code you refer to, this is currently implemented only for Bluetooth Audio connections in function `parse()`. – NFC guy Oct 29 '12 at 07:29
  • 1
    What is the state today? Thank you – igr Mar 05 '16 at 15:21
2

I've created an app which actually writes networks to tag in a standardized way - the problem is that Android does not currently recognize the handover records and automagically add them. And maybe that is all right - after all there is more to adding a network than just adding a network; you might for example verify the composer of the tag contents and so on.

Also, if you'd like to write more than one network to a tag, there might simply not be enough space to do it in the right (using standardized records) way.

ThomasRS
  • 8,215
  • 5
  • 33
  • 48
1

I may have the wrong end of the stick but with the app nfc tools downloaded form the play store you can write a wifi network onto a tag that when scanned with defult android 5.0.2. On a nexus 7 2013 opens a message box asking confirmation formthe wifi connection, although this has always failed bar o

grant page
  • 11
  • 1
  • 3
    Yes this is an old question from '12. In Lollipop I can long press an encrypted network in the WIFI settings and select "write to NFC tag". When scanning the tag, connecting to the network works for my Nexus 4 and 5 with Lollipop. – Alex Apr 01 '15 at 14:56
0

A URI of the form WIFI:T:WPA;S:SSID;P:PASSPHRASE;; will set WiFi if encoded to a QR code and scanned; but when encoded to an NFC tag it is unrecognized as a URI. This suggests to me that the NFC API is deficient in Android.

  • 4
    As far as I can tell, the handler for that string (is it even a URI?) is in ZXing's Barcode Scanner, not the Android OS. If that's the case, it seems unreasonable to expect unrelated Android components to be able to handle it. – Ian Ni-Lewis Oct 29 '12 at 02:28