Android Question MifareClassic Card

dibesw

Active Member
Licensed User
Longtime User
Hi
i am using mifare classic tool to read a card.
This works well
All this code works:
Sub Activity_Resume
    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("TAG_DISCOVERED") Then
        Dim techs As List = nfc.GetTechList(si)
        Log($"Techs: ${techs}"$)
        If techs.IndexOf("android.nfc.tech.MifareUltralight") > -1 Then
            TagTech.Initialize("TagTech", "android.nfc.tech.MifareUltralight" , si)
            TagTech.Connect
        Else If techs.IndexOf("android.nfc.tech.MifareClassic") > -1 Then
            TagTech.Initialize("TagTech", "android.nfc.tech.MifareClassic" , si)
            TagTech.Connect
        Else
            ToastMessageShow("Tag does not support Ndef.", True)
        End If
    End If
End Sub

Private Sub TagTech_Connected (Success As Boolean)
    Dim key() As Byte = Array As Byte(0xA0,0xA1,0xA2,0xA3,0xA4,0xA5)
    Dim sector As Int=0
    TagTech.RunAsync("Authenticate", "authenticateSectorWithKeyA", Array(sector, key), 0)
End Sub

Private Sub Authenticate_RunAsync (Flag As Int, Success As Boolean, Result As Object)
    Log($"Finished trying to auth. Success=${Success}, Flag=${Flag}"$)
    If Success Then
        Dim blockIndex As Int=0
        TagTech.RunAsync("ReadBlock","readBlock",Array(blockIndex),0)
    End If
End Sub

Private Sub ReadBlock_RunAsync(Flag As Int, Success As Boolean, Result As Object)
    Log($"Finished trying to read. Success=${Success}, Flag=${Flag}"$)
    Log(LastException)
    If Success Then
        If Result<>Null Then
            Dim myBlock() As Byte = Result
        End If
    End If
End Sub

Is there are any examples how to WRITE records to MifareClassic tech using NFC library?
This not work:
WriteNdef(Array(nfc.CreateMimeRecord("text/plain", flTxt1.Text.GetBytes("UTF8")), _
                    nfc.CreateMimeRecord("text/plain", flTxt2.Text.GetBytes("UTF8"))))



Private Sub WriteNdef (Records() As Object)
    Dim RecordsJO As JavaObject
    RecordsJO.InitializeArray("android.nfc.NdefRecord", Records) 'I DON'T KNOW WHAT TO PUT IN HERE
    Dim message As JavaObject
    message.InitializeNewInstance("android.nfc.NdefMessage", Array(RecordsJO))  'I DON'T KNOW WHAT TO PUT IN HERE
    TagTech.RunAsync("WriteBlock", "writeBlock", Array(message), 0)
End Sub

Private Sub WriteBlock_RunAsync (Flag As Int, Success As Boolean, Result As Object)
    ToastMessageShow(Success,True)
    Log($"Writing completed. Success=${Success}, Flag=${Flag}"$)
    If Success Then
        ListView1.AddSingleLine("Write ok:"&Result)
    Else
        ListView1.AddSingleLine("Write error:"&Result)
 
    End If
End Sub
Thanks for any helps
 
Last edited:
Top