Good morning everyone,
I have this problem where I need to read and write to the first page of the second sector of a Mifare Classic card. To read the tag, following the example posted by @Erel NFC - Reading and Writing, I used the TagTechnology library, but when I try to read the first page of sector 1, highlighted in red in the attached image, I get an error.
To access that page, I used page index 4 because I noticed that from index 0 to 3 I can read and write without any problems. Therefore, I suppose I need to tell the library to read the next sector of the card and then page 0, but I have no idea how to do it using the TagTechnology library. Also, not all the methods described in the Android documentation seem to work with the B4A porting.
Every thingh works good until I use blockIndex = 4 and I try ro read the block using TagTech.RunAsync( "readBlock4","readBlock", Array(blockIndex), 0).
Any suggestions?
I have this problem where I need to read and write to the first page of the second sector of a Mifare Classic card. To read the tag, following the example posted by @Erel NFC - Reading and Writing, I used the TagTechnology library, but when I try to read the first page of sector 1, highlighted in red in the attached image, I get an error.
To access that page, I used page index 4 because I noticed that from index 0 to 3 I can read and write without any problems. Therefore, I suppose I need to tell the library to read the next sector of the card and then page 0, but I have no idea how to do it using the TagTechnology library. Also, not all the methods described in the Android documentation seem to work with the B4A porting.
sample code:
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private nfc As NFC
Private TagTech As TagTechnology
...
..
..
Sub Activity_Resume
Try
nfc.EnableForegroundDispatch
LogColor("[activity Resume][nfc] [EnableForegroundDispatch] ",Colors.Magenta)
Dim si As Intent = Activity.GetStartingIntent
If si.IsInitialized = False Or si = prevIntent Then Return
LogColor($"[activity resume][intent][new][${si.Action}]"$,Colors.Magenta)
prevIntent = si
Dim tag As JavaObject
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}"$)
Dim Id0() As Byte
Dim Id(8) As String
Dim jTagTech As JavaObject
'NfcA
If techs.IndexOf("android.nfc.tech.NfcA")> -1 Then
TagTech.Initialize("TagTech", "android.nfc.tech.MifareClassic", si)
TagTech.Connect
jTagTech = TagTech
tag = jTagTech.RunMethod("getTag", Null)
Id0 = tag.RunMethod("getId", Null)
.....
.....
.....
Private Sub TagTech_Connected (Success As Boolean)
If Success Then
TagTech.RunAsync("Authenticate", "authenticateSectorWithKeyA", Array(sector, key), 0)
....
....
Private Sub Authenticate_RunAsync (Flag As Int, Success As Boolean, Result As Object)
If Success then
dim as int blockIndex = 1
TagTech.RunAsync( "readBlock1","readBlock", Array(blockIndex), 0)
....
....
Private Sub readBlock1_RunAsync(Flag As Int, Success As Boolean, Result As Object)
Log($"Finished trying to read block1. Success=${Success}, Flag=${Flag}"$)
If Success Then
dim as int blockIndex = 2
TagTech.RunAsync( "readBlock2","readBlock", Array(blockIndex), 0)
Any suggestions?