I have developed a system that can read NFC tag using a reader with PN532 chip. It works ok. I can read Mifare Classic and Mifare Ultralight tag.
Now I'd like to use a Nexus Tablet with Android 4.4.2 to emulate a tag. I have no experience with android development but I think it is possible.
I have set NFC communication in the Nexus Tablet but I think I have to download or write some application to emulate a Tag and an NDEF communication.
What is the easiest way?
That depends on what Nexus tablet you have:
Nexus 7 (first generation/2012 version): This device uses NXP's PN544 NFC controller. It seems that it's currently not possible to perform host-based card emulation with Android 4.4+ on these devices (see this question and my answer here).
Nexus 7 (second generation/2013 version) and Nexus 10: These devices use Broadcom's NFC controller. Therefore, you can use Android 4.4's HCE API to emulate a contactless smartcard.
With Android's HCE API you will emulate an ISO 14443-4 smartcard and you can only communicate using the application selection and APDU format defined in ISO 7816-4. You would first create and register a HCE service (see the API guide). Then you can process incoming APDUs using the service's processCommandApdu()
method (see this answer).
If your reader-side application currently only processes MIFARE Classic and Ultralight, you would have to extend it to also communicate with ISO 14443-4/APDU-based smartcards. (Emulation of non-APDU based cards like MIFARE Classic and Ultralight is not possible on top of ANdroid's HCE API.) The PN532 will typically handle the bigger part of this for you, so once you discover such a smartcard (e.g. with InListPassiveTarget
) it should automatically handle the ISO 14443-4 transport protocol and you can directly send APDU commands using the InDataExchange
command.
If you want to exchange NDEF messages over HCE, once you have APDU-based communication up and running, you could implement the NFC Forum's Type 4 Tag Operation specification (get it from the NFC Forum's website) within the Android HCE service to emulate a Type 4 NDEF tag.
来源:https://stackoverflow.com/questions/24143832/android-4-4-2-pn532-nfc-reader-and-nfc-card-emulation