This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun readFromNFC(ndef: Ndef) { | |
try { | |
ndef.connect() | |
val ndefMessage = ndef.ndefMessage | |
val message = String(ndefMessage.records[0].payload) | |
Log.d(TAG, "readFromNFC: $message") | |
mTvMessage.text = message | |
ndef.close() | |
} catch (e: IOException) { | |
e.printStackTrace() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun writeToNfc(ndef: Ndef, message: String) { | |
mTvMessage!!.text = "write semething" | |
if (ndef != null) { | |
try { | |
ndef.connect() | |
val mimeRecord = NdefRecord.createMime( | |
"text/plain", | |
message.toByteArray(Charset.forName("US-ASCII")) | |
) | |
ndef.writeNdefMessage(NdefMessage(mimeRecord)) |