Share Wifi credentials via NFC tag without special apps

大憨熊 提交于 2019-12-02 15:11:37

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.

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.

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.

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!