Hello chfajardo:
I'm interested in to read Mifare UID, not the data. Can you please post an example of your procedure?
Thanks in advance.
Of course!
Be aware that only a few smartphones are able to read Mifare Cards using NFC, but it is worth a try!
This is the code for reading the NFC UID:
Put this in Process_Globals:
Private nfcIntent As Intent
Sub ConvertToUnsigned(b As Byte) As Int
Return Bit.And(b, 0xFF)
End Sub
Sub read_NFC_UID(nfcIntent1 As Intent) As String
Dim XID(20) As Byte
Dim i As Int
Dim bc As ByteConverter
Dim NFC_UID As String
NFC_UID = ""
If NFC.IsNdefIntent(nfcIntent1) Then
XID=NFC.GeTagtUID(nfcIntent1)
For i = 0 To NFC.GeTagtUID(nfcIntent1).Length-1
XID(i)= ConvertToUnsigned(XID(i))
Next
NFC_UID = bc.HexFromBytes(XID)
End If
Return NFC_UID
End Sub
In the Activity_Resume, put this:
nfcIntent = Activity.GetStartingIntent
NFC_UID = read_NFC_UID(nfcIntent)
I am using these libraries:
byteconverter, core, mul, nfc, nfcforeground and rsnfctagwriter
But i think you can do it with only:
byteconverter, core, nfc, nfcforeground
Also, put this on manifest editor:
AddActivityText(main, <intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain" />
</intent-filter>)
AddActivityText(main, <intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>)
I hope it helps you!