1
votes

I am working on an app that will be deployed on a NFC enabled device. I am trying to enable authentication using NFC, so that a user can scan another NFC device such as phone to authenticate.

I went through the NFC documentation that Android has at http://developer.android.com/guide/topics/connectivity/nfc/nfc.html

I am not able to get my use case working. Here is what I am trying to do:

  1. Deploy app in Device A.
  2. app on Device A will only try to scan for NFC when app is in foreground and is in Login Activity.
  3. User can bring in Device B/NFC tag near Device A, Login Activity will authenticate the user.

I hope this is possible using NFC in Android. My search leads me to example that launches app when NFC is detected but that is not what i am after.

1
I think maybe you are looking for Host-based Card Emulation (HCE)? This available starting in KitKat. See developer.android.com/guide/topics/connectivity/nfc/hce.html.Paul Ratazzi

1 Answers

5
votes

If you want to communicate beween two Android devices by using one as an emulated tag and the other as reader/writer (as opposed to transfering NDEF messages between two devices using Android Beam, which is based on NFC peer-to-peer mode), you could Android HCE (one one device) in combination with reader/writer mode (on the other device).

However, building a solution like this has some limitations. Regarding the emulating side, you have the following limitations and requirements:

  • Android HCE requires the emulating device to run Android 4.4 or later.
  • The emulating device needs to support host-based card emulation. Not all Android 4.4+ devices that have NFC also support HCE. For instance, all (most?) devices that contain NXP's PN544 NFC controller do not curently support HCE.
  • You can only emulate ISO/IEC 7816-4 appliction structures on top of ISO/IEC 14443-4. In case you want to emulate an NFC tag with NDEF data, this would be equivalent to an NFC Forum Type 4 tag. But you are, of course, not limited to emulating NDEF-style NFC tags.

However, an NFC tag (or rather a smartcard application) that is emulated like this imposes some requirements/limitations on the reader side as well:

  • Android's HCE capabilities run in parallel with its peer-to-peer mode capablities (regardless of whether the device has support for Android Beam enabled or not). As a consequence, other Android devices will detect Android HCE devices as peer-to-peer devices and, by default, communicate with them in peer-to-peer mode. Therefore, other Android devices will normally be unable to access an Android HCE emulated smartcard application.
  • Only starting with Android 4.4, you can disable peer-to-peer mode discovery by using the reader mode API. So you need Android 4.4+ on the reader side in order to access the emulated NFC tag.
  • This also prevents automatically starting an app on the second device upon discovery of the first device, so you can only use an Android HCE emulated smartcard application in combination with an activity that already runs in the foreground on the reading device.