Android 无需特殊应用即可通过 NFC 标签共享 Wifi 凭据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10081068/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Share Wifi credentials via NFC tag without special apps
提问by Christian L
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...)
我正在寻找一种方法来创建一个 NFC 标签,该标签可以共享我的网络的 wifi 凭证,而我的客人不必在他们的手机上安装任何特殊的 NFC 应用程序(手机附带的除外)。我一直在寻找应用程序和服务,如 NFC Tag Writer、WifiTap、NFC Task Launcher 和 NFCLabels.com,但在我看来,我需要在访客移动设备上安装应用程序才能使用它,但我无法对其进行测试,因为我只有一部支持 NFC 的手机可用。(是的,我知道,白白地扭曲我的大脑,但是见鬼,奇怪的行为并不是什么新鲜事......)
My closest clue is that WifiTap states that:
我最接近的线索是 WifiTap 声明:
The app processes URIs in the format of wifi://[network ssid]/[wep|wpa|open]/[network key]
该应用程序以 wifi://[network ssid]/[wep|wpa|open]/[network key] 格式处理 URI
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?
如果这实际上是普遍的,这将意味着我可以做我想做的事,但我还没有找到任何确认。那么,如何才能完成我想要的事情,并且我是否在使用 WifiTap 的线索走在正确的轨道上?
采纳答案by NFC guy
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.
这种情况有一个官方标准:NFC 论坛连接切换技术规范。但是,Android 目前不支持此功能。我认为目前没有任何方法可以在没有专用应用程序帮助的情况下使用 NFC 传输 WiFi 凭证。
One way of going about this is to create (or find) an app in the Google Play Store that has the following properties:
解决此问题的一种方法是在 Google Play 商店中创建(或查找)具有以下属性的应用程序:
- Intent filter for ACTION_NDEF_DISCOVERED and as URI the URL of the app in the Play Store.
- Intent filter for ACTION_NDEF_DISCOVERED and as type some proprietary type (e.g. a MIME type)
- ACTION_NDEF_DISCOVERED 的意图过滤器和应用程序在 Play 商店中的 URL 作为 URI。
- ACTION_NDEF_DISCOVERED 的意图过滤器和某些专有类型(例如 MIME 类型)的类型
Then you can create tags with an NDEF message containing the following NDEF records:
然后,您可以使用包含以下 NDEF 记录的 NDEF 消息创建标签:
- SmartPoster record with Play Store URI and some descriptive text (e.g. name of the app)
- Record of proprietary type containing the WiFi credentials
- Android Application Recordfor the app
- 带有 Play 商店 URI 和一些描述性文本(例如应用程序名称)的 SmartPoster 记录
- 包含 WiFi 凭证的专有类型记录
- 该应用程序的Android 应用程序记录
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.
第三条记录将确保始终启动正确的应用程序,或者设备用户将被重定向到 Play 商店进行安装。然而,这仅适用于 ICS,但第一条记录(与第一条意图过滤器结合)在 Gingerbread 上具有相同的用途。
回答by Bruno Parmentier
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.
正如 Alex 在评论中所写,您现在(自 Lollipop 起)可以直接从 Android Wi-Fi 设置写入包含 Wi-Fi 凭据的标签:长按网络 →写入 NFC 标签。
It seems to be an NDEF-formatted tag with the application/vnd.wfa.wsc
MIME type and a "WPS NFC" token.
它似乎是一个 NDEF 格式的标签,带有application/vnd.wfa.wsc
MIME 类型和“WPS NFC”令牌。
The relevant source code can be found in platform/packages/apps/Settings/src/com/android/settings/wifi/WriteWifiConfigToNfcDialog.java
.
相关的源代码可以在 中找到platform/packages/apps/Settings/src/com/android/settings/wifi/WriteWifiConfigToNfcDialog.java
。
回答by ThomasRS
I've created an appwhich 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.
我创建了一个应用程序,它实际上以标准化的方式编写网络以进行标记 - 问题是 Android 目前无法识别切换记录并自动添加它们。也许那没问题——毕竟添加网络不仅仅是添加网络;例如,您可以验证标签内容的作曲家等。
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.
此外,如果您想将多个网络写入一个标签,则可能没有足够的空间以正确的方式(使用标准化记录)来完成。
回答by grant page
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
我可能有错误的一端,但使用从 Play 商店下载的应用程序 nfc 工具,您可以将 wifi 网络写入标签,当使用默认的 android 5.0.2 进行扫描时。在 nexus 7 2013 上打开一个消息框,要求确认 wifi 连接,尽管这总是失败 bar o
回答by Angela Slaney
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.
形式为 WIFI:T:WPA;S:SSID;P:PASSPHRASE;; 的 URI 如果编码为二维码并扫描,将设置 WiFi;但是当编码到 NFC 标签时,它无法识别为 URI。这向我表明 NFC API 在 Android 中存在缺陷。