ionic-framework - 通过 ionic 在 NFC 标签上写入 WiFi ssid 和密码
问题描述
我想做的是在 NFC 标签上写一个 wifi 网络,你必须将你的手机撞到标签上,然后你的手机连接到它。我通过 NFC 工具对此进行了测试,并且成功了。
- 尝试用自己的NFC服务方法写 没用,
因为类型是文本。
我正在尝试更改我的 NFC nDef 写入功能的类型,但似乎在文档或在线中找不到它。
打字稿服务 NFC:
WriteNFC(text: string) {
this.writeNfcAlert(text).then(alert => alert.present());
console.log(text);
let message = [this.ndef.textRecord(text)];
let listener = this.nfc
.addNdefListener(
listener => {
this.ndefWrite = true;
},
err => {
this.ndefWrite = false;
}
)
.subscribe(event => {
if (this.ndefWrite) {
this.alertController.dismiss();
this.nfc
.write(message)
.then(() => {
this.alertController.dismiss();
this.presentToast("Successfuly written to tag.");
})
.catch(() => {
this.WriteNFC(text);
this.presentToast("Not able to write to tag, try again.");
});
}
this.alertController.dismiss();
this.ndefWrite = false;
});
}
WriteWiFiNFC(){
this.writeNfcAlert("new WiFi connection").then(alert => alert.present());
let message = [this.ndef.TNF_EXTERNAL_TYPE]
}
我可能对 NFC 还不够熟悉。但是我正在尝试找到一种解决方案来更改我的 NFC 标签的类型,以便当我扫描 NFC 标签以查找联系人时,它也会像使用 NFC 工具一样检测到它。
我在这里先向您的帮助表示感谢。
更新:
我发现你必须使用 application/vnd.wfa.wsc
let message = [this.ndef.record(this.ndef.TNF_MIME_MEDIA, "application/vnd.wfa.wsc", "", "Network Name: test Authentication Type:OPEN Encryption Type: NONE Pasword: kak")];
我仍在研究如何添加正确的有效负载,我将查看文档 https://android.googlesource.com/platform/packages/apps/Nfc/+/master/src/com/android/nfc /NfcWifiProtectedSetup.java。
更新 2
发现您必须在 NFC 上写入一些特定变量才能让您的手机将其识别为网络。
- NetworkName
- AuthenticationType
- EncryptionType
- NetworkKey
- MacAddress
解决方案
推荐阅读
- java - 当我使用 JGit 库 DiffFormatter 时,为什么会捕获 IOException?
- machine-learning - scipy.optimize.minimize 找不到最小二乘解决方案
- html - 如何从 Angular 中的另一个组件访问导航栏 css 属性
- redis - 与中央数据库同步的内存数据库
- tensorflow - TensorFlow libcublas 10.0 问题
- python - Python Tkinter 按钮宽度和高度
- javafx - 无法向场景构建器添加字体真棒(缺少类)
- python - 如何从 Pandas 数据框中输入 Plotly 条形图的 x 和 y 值
- javascript - 包含 Vue 后 Laravel 表单损坏
- javascript - Discord JS - 如何获取用户已连接帐户的链接