Android Question Getting UID from an nfc-v tag (NFC2 lib)

pixsys

Member
Licensed User
Longtime User
Hello,
I'm using the nfc2 library to handle nfc-v tags, calling runasync with transceive (and related byte payload).

Is there a way to use the same system to retrieve the Unique Tag Id? As far as i know it should be visible after the _connected event, but i see no way to retrieve it.

I'm using b4a v7.00 beta and NFC2 v2.00

Thanks
 

pixsys

Member
Licensed User
Longtime User
Sure, the code is very standard, it just starts the read procedure
B4X:
Private Sub TagTech_Connected (Success As Boolean)

    Dim CurrentTag As TagTechnology= TagTech  'tagtech is global and used in the connect call in activity_resume
    Log($"Connected: ${Success}"$)

    If Success = False Then
        Log(LastException)
    Else
        Read_Chunks(0,7,"ReadDone",False)
    End If
End Sub
What i noticed while debugging is, at that point the TagTechnology object has an array called mID (inside mtag). Is that the UID? And how can i programmatically access it?

EDIT:
found a possible solution on an old post on these boards:

B4X:
Dim j As JavaObject = TagTech
        Dim tag As JavaObject = j.RunMethod("getTag", Null)
        Dim Id() As Byte = tag.RunMethod("getId", Null)

Testing right now, but seems to work. Still not sure if the same can be achieved throu runasync-> transceive, probably depends on the type of tag
 
Last edited:
Upvote 0
Top