How to a send SNEP GET request from Android

ε祈祈猫儿з 提交于 2019-12-04 18:44:05

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.

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