Skip to content

Instantly share code, notes, and snippets.

@pjwelcome
Created July 26, 2017 19:38
Show Gist options
  • Save pjwelcome/e92456327a9174c958b5f54980bc9fc8 to your computer and use it in GitHub Desktop.
Save pjwelcome/e92456327a9174c958b5f54980bc9fc8 to your computer and use it in GitHub Desktop.
fun createNFCMessage(payload: String, intent: Intent?) : Boolean {
val pathPrefix = "peterjohnwelcome.com:nfcapp"
val nfcRecord = NdefRecord(NdefRecord.TNF_EXTERNAL_TYPE, pathPrefix.toByteArray(), ByteArray(0), payload.toByteArray())
val nfcMessage = NdefMessage(arrayOf(nfcRecord))
intent?.let {
val tag = it.getParcelableExtra<Tag>(NfcAdapter.EXTRA_TAG)
return writeMessageToTag(nfcMessage, tag)
}
return false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment