Android Question NFC UID Read error

Duncan H Williamson

Member
Licensed User
Longtime User
Hi All, I hope someone can point me in the right direction... I have an app which reads NFC tags and utilizes the UID of the tag, up until today this has worked perfectly using the code that Erel and others have provided

B4X:
NFC.EnableForegroundDispatch
    Dim si As Intent = Activity.GetStartingIntent
    If si.IsInitialized = False Or si = prevIntent Then Return
    prevIntent = si
    If si.Action.EndsWith("TECH_DISCOVERED") Or si.Action.EndsWith("NDEF_DISCOVERED") Or si.Action.EndsWith("TAG_DISCOVERED") Then
        Dim techs As List = NFC.GetTechList(si)
        Log($"Techs: ${techs}"$)
        If techs.IndexOf("android.nfc.tech.Ndef") > -1 Then
            TagTech.Initialize("TagTech", "android.nfc.tech.Ndef" , si)           
            TagTech.Connect
        Else
            ToastMessageShow("Tag does not support Ndef.", True)
           
        End If
    End If

the tags I have been using and distributing ( around 20,000 of them) are NXP MIFARE Ultralite ISO 14443-3A and I have had no issues reading the UID on my samsung s7 however today the operating system on this phone updated to android 7 and suddenly I can no longer read the tag UID
I receive the error "Tag does not support Ndef"
I have used another app on my phone called NFC Tools and it still reads the tag and UID without a problem

I urgently need to sort this problem as multiple copies of this app are running on Samsung devices with the risk that they will update their operating system

Regards


Duncan
 

Duncan H Williamson

Member
Licensed User
Longtime User
Hi All, I hope someone can point me in the right direction... I have an app which reads NFC tags and utilizes the UID of the tag, up until today this has worked perfectly using the code that Erel and others have provided

B4X:
NFC.EnableForegroundDispatch
    Dim si As Intent = Activity.GetStartingIntent
    If si.IsInitialized = False Or si = prevIntent Then Return
    prevIntent = si
    If si.Action.EndsWith("TECH_DISCOVERED") Or si.Action.EndsWith("NDEF_DISCOVERED") Or si.Action.EndsWith("TAG_DISCOVERED") Then
        Dim techs As List = NFC.GetTechList(si)
        Log($"Techs: ${techs}"$)
        If techs.IndexOf("android.nfc.tech.Ndef") > -1 Then
            TagTech.Initialize("TagTech", "android.nfc.tech.Ndef" , si)          
            TagTech.Connect
        Else
            ToastMessageShow("Tag does not support Ndef.", True)
          
        End If
    End If

the tags I have been using and distributing ( around 20,000 of them) are NXP MIFARE Ultralite ISO 14443-3A and I have had no issues reading the UID on my samsung s7 however today the operating system on this phone updated to android 7 and suddenly I can no longer read the tag UID
I receive the error "Tag does not support Ndef"
I have used another app on my phone called NFC Tools and it still reads the tag and UID without a problem

I urgently need to sort this problem as multiple copies of this app are running on Samsung devices with the risk that they will update their operating system

Regards


Duncan
a bit of an update.... further testing has shown that it cannot read unformatted tags... if I format the tag using other software the tag UID can be read no problem....
prior to upgrading to android 7 it could read unformatted tags without a problem...
 
Upvote 0

DavideV

Active Member
Licensed User
Longtime User
Add a message, when the read fails, to let the user format the tag through your app.
If the user chooses to continue then write to it an ndef field.

bye
 
Upvote 0

Duncan H Williamson

Member
Licensed User
Longtime User
Add a message, when the read fails, to let the user format the tag through your app.
If the user chooses to continue then write to it an ndef field.

bye
Hi DavideV, although that is an option it will add a huge increased time constraint to the end users who daily read hundreds of tags. I have overcome the problem by making a few small changes, the first is making the change below to the code I posted
B4X:
If techs.IndexOf("android.nfc.tech.NfcA") > -1 Then
            TagTech.Initialize("TagTech", "android.nfc.tech.NfcA" , si)
            TagTech.Connect
        Else
            ToastMessageShow("Tag does not support NfcA.", True)
this allowed the tag to be recognised

I also made the following change
B4X:
Private Sub ReadNdef_RunAsync (Flag As Int, Success As Boolean, Result As Object)
    Log($"Reading completed. Success=${Success}, Flag=${Flag}"$)
   
    'If Success Then
        Dim jo As JavaObject = TagTech
        Dim tag As JavaObject = jo.RunMethod("getTag", Null)
        Dim rawId() As Byte = tag.RunMethod("getId", Null)
        gethive( bc.HexFromBytes(rawId))
           
    'End If
End Sub
so far I have had no issues with errors but will continue testing before releasing it to my users.... hopefully no one updates to android 7 prior to that.

Regards

Duncan
 
Upvote 0
Top