3

I have some questions about the communication between a NFC reader and an Android phone.

The first subject is the Android / NFC reader modus: What is the best way to pass a unique identifier from the NFC reader (ACR122U) to an Android device? ACR122U in peer-to-peer, card emulation, or reader/writer mode? Wich modus are possible? And what is the best mode if you want bi-directional communication?

The second subject is about the listener on the android device: How can a Android reader trigger an Android application? When you tap your phone on the NFC reader, do you need to have the Android application in the front or do you need to write a NFC listener or something while your application is running on the background?

Many thanks.

Michael Roland
  • 39,663
  • 10
  • 99
  • 206
S.Pols
  • 3,414
  • 2
  • 21
  • 42

1 Answers1

3

What is the best way to pass a unique identifier from the NFC reader (ACR122U) to an Android device?

That depends on what you want to achieve.

  • Using the ACR122U in reader/writer mode will basically limit you to using Android 4.4 and later (as Android HCE -- for putting the phone into host-based card emulation mode -- is only supported from 4.4 onwards).
  • Peer-to-peer mode will work but will effectively limit you to sending one data packet (or one message) into a single direction.
  • Using the ACR122U in card emulation mode will permit you to perform true bidirectional communication (i.e. to send multiple data packets into both direction).

See this answer for a list of further literature.

Which modes are possible?

All three modes are possible but give you different degrees of freedom.

And what is the best mode if you want bi-directional communication?

See above, using the ACR122U in card emulation mode and the phone in reader/writer mode will permit bi-directional communication on all Android versions. The phone has the role of the interrogator (in a command-response protocol) in this case.

If you only want/need to support Android 4.4 and later, you could just as well use the phone in HCE (host-based card emulation) mode and the ACR122U in reader/writer mode.

When you tap your phone on the NFC reader, do you need to have the Android application in the front or do you need to write a NFC listener or something while your application is running on the background?

  • If you are using Android HCE (phone as emulated card): In this case, the communication is handled by a background service. No user interface is needed on the device. If you want to start a user interface upon scanning the ACR122U with a phone, I suggest that you stick with using the Android in reader/writer or peer-to-peer mode (though you could start a UI through the HCE service too).

  • If you are using the Android in reader/writer mode: You need an app running in the foreground to communicate with an NFC tag/smartcard/emulated card. However, the app can be started automatically upon detection of the tag. You would use an intent filter that matches either the tag's technology or (better yet) matches an NDEF record that is stored on the tag. See this for further details.

Community
  • 1
  • 1
Michael Roland
  • 39,663
  • 10
  • 99
  • 206
  • do you know if there is any example of card emulation with a ACR122u? – S.Pols Jul 08 '14 at 12:52
  • See the post linked in "*See [this answer](http://stackoverflow.com/a/24151202/2425802) for a list of further literature.*" – Michael Roland Jul 09 '14 at 05:16
  • @MichaelRoland "However, the app can be started automatically upon detection of the tag", - how can we do this? Could you share some sample of it? – Vitaliy L May 12 '16 at 15:08
  • @VitaliyLevytskyy A sample would probably be too much for this format. The ACR122U (or whatever NFC device) is in card emulation mode and responds to commands from the Android phone. In addition the ACR122U would need to implement the protocol of the NDEF tag application (defined by the NFC Forum Type 4 Tag Operation specification). Then you can store an NDEF record for launching the Android app within that NDEF tag application. – Michael Roland May 12 '16 at 15:16
  • @MichaelRoland Pls, see: http://stackoverflow.com/questions/37188472/nfc-card-emulation-with-close-application – Vitaliy L May 12 '16 at 15:27
  • @MichaelRoland Can you discribe how can we start application for transferring NFC data without beam-like additional approve touch? – Vitaliy L May 12 '16 at 15:29
  • @VitaliyLevytskyy Did you read my comment? As I already wrote, you need to emulate a NDEF tag (= NFC Forum Type 4 Tag Operation specification) with the ACR122U. Within that emulated tag application you then hold the data structure (NDEF message) that matches the intent filter (NDEF_DISCOVERED) of your activity on the Android device. – Michael Roland May 12 '16 at 16:09
  • @MichaelRoland could it be done only by using device? not ACR122U. Do you know some info how can I emulate nfc tag from my device? – Vitaliy L May 12 '16 at 16:38
  • @MichaelRoland I am developing an android application to emulate my android phone as a card using the HCE technology. I have an ACR122U-A9 NFC reader. When I hold the device in the top of the reader nothing will happen. How can I fix this? – Rosemary Feb 13 '19 at 09:19