org.opennfc.cardemulation
Interface CardEmulation


public interface CardEmulation

The Card emulation is a feature of the NFC Controller used to emulate a card with the NFC Device.

The following figure depicts the life-cycle of the card emulation:


To create an instance of Card Emulation, use CardEmulationRegistry.createCardEmulation().

Starting the Card Emulation

To emulate a card, a client application calls the method start(). When this method returns successfully, an external reader may start to interact with the simulated card.

Answering to the Reader

When a command is received and analyzed, the answer can be sent back to the reader using the method sendResponse().

Exclusivity

Only one card of a given type can be emulated at the same time. If several applications try to simultaneously emulate the same card type, the first application obtaining the connection has the exclusive use of the service. The other application are rejected. The card emulation can be open when the owner application stops the card emulation.

Stopping the Card Emulation

The card emulation is stopped by calling the method stop().

Since:
Open NFC 4.0

Method Summary
 void sendResponse(byte[] response)
          Sends the response of the emulated card to the reader.
 void start(CardEmulationEventHandler handler)
          Starts the emulation of the card.
 void stop()
          Stop the emulation of the card.
 

Method Detail

start

void start(CardEmulationEventHandler handler)
           throws NfcException
Starts the emulation of the card.

Parameters:
handler - a CardEmulationEventHandler whose onEventReceived() method will be called for each event received or onCommandReceived() method will be called for each command received.
Throws:
IllegalArgumentException - if handler is null.
IllegalStateException - if the emulation is already started.
NfcException - in case of NFC error.

stop

void stop()
Stop the emulation of the card. If the emulation is already stopped, this method does nothing.


sendResponse

void sendResponse(byte[] response)
                  throws NfcException
Sends the response of the emulated card to the reader.

Parameters:
response - the buffer with the response data to send to the reader.
Throws:
IllegalArgumentException - if response is null.
NfcException - if the card emulation is stopped or in case of NFC error.

Copyright © 2010-2011 Inside Secure
Except as noted, this content is licensed under Apache 2.0 License.