Android NFC help

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
banjaxd
Posts: 5
Joined: Sat Nov 27, 2021 1:34 pm

Android NFC help

Post by banjaxd » Mon Aug 01, 2022 4:34 pm

Hi

I have a very requirement to read the unique ID of an NFC ID card, and display it on the screen. I've written a simple app which does this but it seems to return incorrect data. The ID should be unique to each card and 14 characters long. The response I receive is 4 characters and appears to be special characters, example below:

Desktop Reader: 0455A50A435291
App Reader: o2}o

I've used the examples in the dictionary and the other posts on the forum which suggest I should be reading the "id" field as below:

Code: Select all

on nfcTagReceived pTag
   put pTag["id"] into tID
   answer tID
end nfcTagReceived
Am I reading the wrong location? Or is this an encoding problem? Perhaps I'm just not understanding what needs to be done. I'd appreciate any help. Looking at other posts it seems Jacques is an expert in this area?

I should say I am new to Android, but I've been using LC (and loving it) for a few years. I'd really appreciate some help.

Thanks. :D

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7228
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Android NFC help

Post by jacque » Tue Aug 02, 2022 9:32 pm

I'm not sure I'm an expert but I did have to figure this out. The ID you're getting is binary and it has to be converted to ASCII before it's useful. You've got the first part correct, you just need to follow up with a conversion.

Code: Select all

on nfcTagReceived pTag
   put pTag["id"] into tID
   put decodeNFC(tID) into tTagID
   answer tTagID
end nfcTagReceived 

function decodeNFC pTagID
  -- convert a binary NFC tag ID to colon-deimited ASCII
  -- pTagID = scanned tag; hardware ID is binary
  local tAsciiTag
  get binaryDecode("H*",pTagID,tAsciiTag) -- contains no colon separators
  repeat with x = len(tAsciiTag) to 4 step -2 -- add colons
    put colon before char x-1 of tAsciiTag
  end repeat
  return tAsciiTag
end decodeNFC
I just tried with the example you posted and I'm only getting 8 characters but that may be a problem with the forum display.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

banjaxd
Posts: 5
Joined: Sat Nov 27, 2021 1:34 pm

Re: Android NFC help

Post by banjaxd » Wed Aug 03, 2022 12:54 pm

Perfect! That's what I was missing, thank you.
I just tried with the example you posted and I'm only getting 8 characters but that may be a problem with the forum display.
Yes, I had to adjust the text when I copied it into the original post as it wouldn't submit otherwise.

Thank you so much :)

Post Reply

Return to “Android Deployment”