Making NFC/Beam more automatic

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 05:26:15

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.

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.

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