I am trying to check if a value read from an NFC tag is equal to a String. The value written in the tag is correctly extracted, but when I try to compare the value with another string, as in the second "if" statement, it will always enter the "else" block.
private fun processNdefMessages(ndefMessages: Array<NdefMessage?>) {
var msg = ""
for (curMsg in ndefMessages) {
if (curMsg != null) {
// get the text written in the tag
msg = String(curMsg.getRecords().get(0).getPayload())
}
}
textFromTag = msg
if (textFromTag.equals("enjacket1")) {
Toast.makeText(applicationContext, "jacket1", Toast.LENGTH_LONG).show()
} else {
Toast.makeText(applicationContext, "$textFromTag", Toast.LENGTH_LONG).show()
}
EDIT: Also, when I read the payload from the tag, it always starts with "en" and then the actual string. This is why I compare the textFromTag
with "enjacket1". I tried to eliminate the first two charaacters, but nothing seems to make a change to it...