INNER CODE UNIT · Kotlin

onTagDiscovered

dotintent/flutter-nfc-reader · android/src/main/kotlin/it/matteocrippa/flutternfcreader/NfcHandler.kt:19

    override fun onTagDiscovered(tag: Tag) {
        val type = call.argument<String>("path")
                ?: return result.error("404", "Missing parameter", null)
        val payload = call.argument<String>("label")
                ?: return result.error("404", "Missing parameter", null)
        val nfcRecord = NdefRecord(NdefRecord.TNF_EXTERNAL_TYPE, type.toByteArray(), byteArrayOf(), payload.toByteArray())
        val nfcMessage = NdefMessage(arrayOf(nfcRecord))
        writeMessageToTag(nfcMessage, tag)
        val data = mapOf(kId to "", kContent to payload, kError to "", kStatus to "write")
        val mainHandler = Handler(Looper.getMainLooper())
        mainHandler.post {
            result.success(data)
        }
        unregister()
    }

    private fun writeMessageToTag(nfcMessage: NdefMessage, tag: Tag?): Boolean {
        val nDefTag = Ndef.get(tag)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…