By default the Agnos SDK is configured to handle all requests coming from the native framework, including interactions with the card (detection + APDU exchanges).
To directly interact with the card in the application (rather than in the SDK), please turn on the fullForward
mode. To do so, simply call the setFullForward()
API after having instantiated the Agnos object.
Ex:
private val agnos = Agnos(this) agnos.setFullForward(true)
Once the fullForward
mode is activated, all the events and request coming from the framework will be sent to the dedicated callback handleDevEvent()
and handleDevRequest()
.
For contactless cards management the important requests/events ID to catch are:
RPC_CMDID_REQ_PCD_DETECT
RPC_CMDID_REQ_PCD_REMOVE
RPC_CMDID_REQ_PCD_XCHNG
Ex:
fun handleDevEvent(data: ByteArray) { val cmd = data[0].toInt() if (fullForward) { listener.handleDevEvent(data) return } if (cmd == Rpc.Cmd.RPC_CMDID_EVT_PCD_SET_FIELD.id) { setField(data[1]) } else { listener.handleDevEvent(data) } } @Throws(IOException::class) fun handleDevRequest(data: ByteArray): ByteArray? { val cmd = data[0].toInt() if (fullForward) return listener.handleDevRequest(data) /* Handles NFC requests locally. Pass the rest onto the higher level app */ return when (cmd) { Rpc.Cmd.RPC_CMDID_REQ_PCD_DETECT.id -> { val resp = ByteArray(1) val timeout = data[1].toInt() resp[0] = detectCard(timeout).toByte() resp } Rpc.Cmd.RPC_CMDID_REQ_PCD_REMOVE.id -> { removeCard() ByteArray(1) } Rpc.Cmd.RPC_CMDID_REQ_PCD_XCHNG.id -> { val apdu = data.copyOfRange(1, 1 + data.size - 1) sendApdu(apdu) } else -> { listener.handleDevRequest(data) } } }