本文介绍了如何从Android发送SNEP GET请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个NFC阅读器ACS ACR122U,我想从我的Android手机向它发送数据.

I have an NFC reader ACS ACR122U and I want to send data from my Android phone to it.

我发现了许多示例,这些示例说明了如何以P2P模式连接两个设备以及如何将数据从手机发送到ACR122U,但是我的台式机服务器(ACR122U)始终会收到SNEP PUT请求.我会发送GET请求,但是我只能找到使用NDEF系统内置的Android的示例,而无需指定PUT或GET请求.

I have found many examples on how to connect my two devices in P2P mode and how to send data from my phone to the ACR122U, but my desktop server (ACR122U) always receives a SNEP PUT request. I would send a GET request but I can find only examples that use Android built in NDEF system without specifing PUT or GET request.

如何将SNEP GET请求从我的Android设备打包并发送到ACR122U?

How can I package and send a SNEP GET request from my Android device to an ACR122U?

推荐答案

简短的回答:不能.

Android API不允许您实现自定义LLCP服务.在Android设备上实现的唯一LLCP服务是NFC论坛默认SNEP服务器(服务名称urn:nfc:sn:snep,服务访问点地址4),以及由于传统原因,Android NDEF推送协议(类似于SNEP,但其历史可以追溯到SNEP规范已发布).

The Android API does not allow you to implement custom LLCP services. The only LLCP services implemented on Android devices are the NFC Forum Default SNEP Server (service name urn:nfc:sn:snep, service access point address 4) and, for legacy reasons, the Android NDEF push protocol (similar to SNEP but dates back to times before the SNEP specification was published).

虽然SNEP协议规范定义了GET请求以从另一台设备提取NDEF消息,但NFC论坛默认SNEP服务器被定义为仅接受PUT请求. GET请求必须被该SNEP服务器拒绝.

While the SNEP protocol specification defines a GET request to pull an NDEF message from another device, the NFC Forum Default SNEP Server is defined to only accept PUT requests. GET requests must be rejected by that SNEP server.

摘自NFC论坛简单NDEF交换协议技术规范(1.0版):

From the NFC Forum Simple NDEF Exchange Protocol technical specification (Version 1.0):

默认服务器将不接受Get请求.对Get请求消息的适当响应未实现.

The default server SHALL NOT accept Get requests. The appropriate response for a Get request message is Not Implemented.

因此,您只能将NDEF消息推送到NFC论坛默认SNEP服务器,而不能反过来.

So you can only push NDEF messages to the NFC Forum Default SNEP Server and not the other way round.

因此,如果要通过对等模式向 Android设备发送 NDEF消息,则需要实施 SNEP client .然后,您可以让该客户端连接到Android设备上的SNEP服务器(服务名称为urn:nfc:sn:snep),并使用PUT请求向其推送NDEF消息.

Hence, if you want to send an NDEF message to an Android device through peer-to-peer mode, you need to implement a SNEP client on the ACR122U side. You can then let that client connect to the SNEP server on the Android device (at service name urn:nfc:sn:snep) and push the NDEF message to it using a PUT request.

如果您想通过对等模式从Android设备接收 NDND消息,则需要实现 SNEP 服务器 .然后,Android SNEP客户端将连接到您的SNEP服务器,并再次使用PUT请求将等待的NDEF消息(例如,通过NfcAdapter.setNdefPushMessage()注册的消息)推送到该服务器.

If you want to receive an NDEF message from an Android device through peer-to-peer mode, you need to implement a SNEP server on the ACR122U side. The Android SNEP client will then connect to your SNEP server and push the waiting NDEF message (e.g. registered through NfcAdapter.setNdefPushMessage()) to it using, again, a PUT request.

这篇关于如何从Android发送SNEP GET请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 20:49