I'm trying to emulate an NFC tag with my Nexus 5 according to this document, but my service is never invoke. Should I turn off Android beam?
I'd like to emulate a simple tag containing a url.
The reader is a Nexus 7 (2012) and I've figured out the process like a simple scan of a NFC tag using Android beam on Nexus 7.
In addition I'm a bit confused about aid-filter name. Is there a list of them?
I'm sure that I don't understand something. Thanks
First of all (though this does not directly answer your question), the preferred way to transfer a URL between two Android NFC device is to use Android Beam (peer-to-peer mode). Android HCE (Host Card Emulation) is typically intended for emulation of contactless smartcard applications other than NFC tags.
Do I need to turn off Android Beam in order to use Android HCE?
No, Android HCE is not influenced by the on/off setting of Android Beam. Actually, even if Beam is turned off an Android NFC device will still perform peer-to-peer mode link activation.
I'd like to emulate a simple tag containing a URL.
Android HCE emulates smartcard applications based on ISO/IEC 14443-4 and ISO/IEC 7816-4. Thus, if you want to emulate an NFC tag with this, you would need to implement the NFC Forum's Type 4 Tag Operation specification in your Android HCE service. The NFC Forum's specifications are freely available on their website.
To summarize the requirements of this specification:
- You need to register your service for the NFC Forum Type 4 tag application AID:
D2760000850101
. Your service needs to respond with status code success (
0x9000
) to a SELECT (by DF name) APDU for that AID:> 00 A4 04 00 07 D2760000850101 00 < 9000
Your service needs to respond with status code success to a SELECT (by EF ID) APDU for the capability container (CC) file (
E103
):> 00 A4 00 0C 02 E103 < 9000
Your service needs to responds with the CC (or parts of it) upon receiving a READ BINARY APDU (after the CC file had been selected):
> 00 B0 Offset_High Offset_Low Length < <Length bytes of the CC starting at Offset> 9000
Your service needs to respond with status code success to a SELECT (by EF ID) APDU for the NDEF file (EF ID as defined in the CC):
> 00 A4 00 0C 02 <EF ID> < 9000
Your service needs to responds with the NDEF file content (or parts of it) upon receiving a READ BINARY APDU (after the NDEF file had been selected):
> 00 B0 Offset_High Offset_Low Length < <Length bytes of the NDEF file starting at Offset> 9000
I want a second Android device to automatically pick up the URL.
That's the problematic part and the reason why Beam is the preferred way to go. Even if you emulate an NFC Forum Type 4 tag with one Android device, putting two Android devices together will still result in them establishing a peer-to-peer link (even if Beam is turned off!). Thus, the second Android device will not detect your HCE emulated card as an NFC tag. The only way to overcome this limitation is to use the NFC Reader mode API (new in Android 4.4) on the second device. However, in that case, you would need to have an app on the receiving device that is active in the foreground (that's the only way to enable the Reader mode API).
来源:https://stackoverflow.com/questions/23155719/host-card-emulation-on-android-4-4-kitkat-and-above-with-nexus-5