How to a send SNEP GET request from Android

谁说胖子不能爱 提交于 2019-12-21 23:20:05

问题


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

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.

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


回答1:


Short answer: You can't.

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).

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.

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

The default SNEP server provides a logical inbox. A client connected to the default server can place NDEF messages into the inbox using Put request messages. [...]

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

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

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.

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.



来源:https://stackoverflow.com/questions/41399806/how-to-a-send-snep-get-request-from-android

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