Making NFC/Beam more automatic

五迷三道 提交于 2019-12-01 03:07:29

问题


I am adding NFC/Beam capabilities to my app and I would like it to work as automatically as possible. I would like to get rid of the "Touch To Beam" screen from the sender and the "New tag scanned" screen from the receiver. Basically, I want it to work like it does in the Samsung commercial!!! I read in stackoverflow that it seems like there may not be a way to get rid of the "Touch To Beam" screen, however I am hoping someone has some updated information or knows how to remove the receiver screen. Thanks!


回答1:


Sending side

When using NFC peer-to-peer communication (aka Android Beam) between two Android (4.0+) devices, there is no way to avoid the Beam UI. So it is not possible to transfer data without the "Touch to Beam".

Before Android Beam (effectively Android 2.3.3-2.3.7), this was possible through foreground NDEF push (which is now (a) deprecated and (b) on Android 4.0+ implemented through Beam). In that case NDEF messages where immediately transfered without the "Touch to Beam" window.

Starting with Android 4.4, there is the possibility to communicate between two Android devices over NFC without the Beam UI (actually without using Android Beam and peer-to-peer mode at all): If both devices are 4.4+, one device can use Android HCE to emulate a contactless smartcard and one device can use the reader-mode API (this only works with the reader-mode API introduced in 4.4, so both devices need to be 4.4+) to communicate with the emulated smartcard.

Receiving side

If you send an NDEF message through Beam, you can at least get the receiving side to do what you want. In that case, you need to register a proper NDEF_DISCOVERED intent filter (that matches the record type/data type of the first NDEF record of the sent NDEF message) in your app's AndroidManifest.xml.




回答2:


You could manually handle the beaming via foregroundDispatch http://developer.android.com/guide/topics/connectivity/nfc/advanced-nfc.html This will allow your app to automatically send.

As for receiving you can use an activity to just catch the intent and forward it onto a service for processing.



来源:https://stackoverflow.com/questions/13542697/making-nfc-beam-more-automatic

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