adapter.enableReaderMode(activity, {
val handle = UUID.randomUUID().toString()
tags[handle] = it
activity.runOnUiThread { channel.invokeMethod("onDiscovered", getTagMap(it).toMutableMap().apply { put("handle", handle) }) }
}, getFlags(call.argument<List<String>>("pollingOptions")!!), null)
class Provider : IProvider {
private var mTagCom: IsoDep? = null
@Throws(CommunicationException::class)
override fun transceive(pCommand: ByteArray): ByteArray {
val response: ByteArray = try {
// send command to emv card
mTagCom!!.transceive(pCommand)
} catch (e: IOException) {
throw CommunicationException(e.message)
}
return response
}
override fun getAt(): ByteArray {
// For NFC-A
return mTagCom!!.historicalBytes
// For NFC-B
// return mTagCom.getHiLayerResponse();
}
fun setmTagCom(mTagCom: IsoDep?) {
this.mTagCom = mTagCom
}
}
val provider: IProvider = Provider()
(provider as Provider).setmTagCom(IsoDep.get(it))
val config: EmvTemplate.Config = EmvTemplate.Config()
.setContactLess(true) // Enable contact less reading (default: true)
.setReadAllAids(true) // Read all aids in card (default: true)
.setReadTransactions(true) // Read all transactions (default: true)
.setReadCplc(false) // Read and extract CPCLC data (default: false)
.setRemoveDefaultParsers(false) // Remove default parsers for GeldKarte and EmvCard (default: false)
.setReadAt(true) // Read and extract ATR/ATS and description
val parser = EmvTemplate.Builder() //
.setProvider(provider) // Define provider
.setConfig(config) // Define config
//.setTerminal(terminal) (optional) you can define a custom terminal implementation to create APDU
.build()
val mIsoDep = IsoDep.get(it)
mIsoDep.connect()
val card = parser.readEmvCard()
activity.runOnUiThread {
channel.invokeMethod("onDiscovered", getTagMap(it).toMutableMap().apply {
put("handle", handle)
put("cardNumber", card.cardNumber)
put("holderFirstName", card.holderFirstname)
put("holderLastName", card.holderLastname)
put("type", card.type.getName())
})
}