hi all,
i want to read and write to mifare desfire 4k card
it support tech :
Techs: [android.nfc.tech.IsoDep, android.nfc.tech.NfcA, android.nfc.tech.NdefFormatable]
i want to use android.nfc.tech.NdefFormatable
i modified the sample project, but it didn't work,
there is nothing happened.
no errors, Reading completed. Success=false, Flag=0, Writing completed. Success=false, Flag=0
Ok, i have tried using NXP TagWritter App
when i do 'Erase and Format as NDEF' , result is success
and when to write tags, also success.
but with my code , cannot read and write.
note : this card is not support NDEF tech, but IsoDep, NfcA and NdefFormatable
is my code above (attached in first post) is correct ?, and can be use for NdefFormatable tech ?
is tech beside NDEF can be used for read and write tags ? if can , i need an script examples.. please
attached is screenshot with NXP TagWritter and NXP Reader
Private Sub WriteNdef (Records() As Object)
Dim RecordsJO As JavaObject
RecordsJO.InitializeArray("android.nfc.NdefRecord", Array(nfc.CreateUriRecord("https://www.b4x.com")))
Dim message As JavaObject
message.InitializeNewInstance("android.nfc.NdefMessage", Array(RecordsJO))
TagTech.RunAsync("Format", "format", Array(message), 0)
Wait For Format_RunAsync (Flag As Int, Success As Boolean, Result As Object)
Log("format: " & Success)
Log(Result)
End Sub
Sub Activity_Resume
'forces all nfc intents to be sent to this activity
nfc.EnableForegroundDispatch
Dim si As Intent = Activity.GetStartingIntent
'check that the intent is a new intent
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}"$)
'in this case we are only accessing Ndef tags.
If techs.IndexOf("android.nfc.tech.NdefFormatable") > -1 Then
''TagTech.Initialize("TagTech", "android.nfc.tech.NfcA" , si)
'Connect to the tag
''TagTech.Connect
TagTech.Initialize("TagTech", "android.nfc.tech.NdefFormatable" , si)
TagTech.Connect
WriteNdef(Array(nfc.CreateMimeRecord("text/plain", flTxt1.Text.GetBytes("UTF8")), _
nfc.CreateMimeRecord("text/plain", flTxt2.Text.GetBytes("UTF8"))))
Else
ToastMessageShow("Tag does not support Ndef.", True)
End If
End If
End Sub
Private Sub WriteNdef (Records() As Object)
Dim RecordsJO As JavaObject
RecordsJO.InitializeArray("android.nfc.NdefRecord", Array(nfc.CreateUriRecord("https://www.b4x.com")))
Dim message As JavaObject
message.InitializeNewInstance("android.nfc.NdefMessage", Array(RecordsJO))
TagTech.RunAsync("Format", "format", Array(message), 0)
Wait For Format_RunAsync (Flag As Int, Success As Boolean, Result As Object)
Log("format: " & Success)
Log(Result)
End Sub
Sub Activity_Resume
'forces all nfc intents to be sent to this activity
nfc.EnableForegroundDispatch
Dim si As Intent = Activity.GetStartingIntent
'check that the intent is a new intent
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}"$)
'in this case we are only accessing Ndef tags.
If techs.IndexOf("android.nfc.tech.NdefFormatable") > -1 Then
''TagTech.Initialize("TagTech", "android.nfc.tech.NfcA" , si)
'Connect to the tag
''TagTech.Connect
TagTech.Initialize("TagTech", "android.nfc.tech.NdefFormatable" , si)
TagTech.Connect
Else
ToastMessageShow("Tag does not support Ndef.", True)
End If
End If
End Sub
Private Sub WriteNdef (Records() As Object)
Dim RecordsJO As JavaObject
RecordsJO.InitializeArray("android.nfc.NdefRecord", Array(nfc.CreateUriRecord("https://www.b4x.com")))
Dim message As JavaObject
message.InitializeNewInstance("android.nfc.NdefMessage", Array(RecordsJO))
TagTech.RunAsync("Format", "format", Array(message), 0)
Wait For Format_RunAsync (Flag As Int, Success As Boolean, Result As Object)
Log("format: " & Success)
Log(Result)
End Sub
Private Sub TagTech_Connected (Success As Boolean)
Log($"Connected: ${Success}"$)
WriteNdef(Array(nfc.CreateMimeRecord("text/plain", flTxt1.Text.GetBytes("UTF8")), _
nfc.CreateMimeRecord("text/plain", flTxt2.Text.GetBytes("UTF8"))))
End Sub
Private Sub TagTech_Connected (Success As Boolean)
Log($"Connected: ${Success}"$)
If Success = False Then
ToastMessageShow("Error connecting to tag", True)
Log(LastException)
Else
WriteNdef(Array(nfc.CreateMimeRecord("text/plain", flTxt1.Text.GetBytes("UTF8")), _
nfc.CreateMimeRecord("text/plain", flTxt2.Text.GetBytes("UTF8"))))
End If
End Sub
It shouldn't be too difficult to implement the code from that link with TagTech.RunAsync.
Something like:
B4X:
'after connection
TagTech.RunAsync("TT", "transceive", Array(Array As Byte(0xA2, 0x03, 0xE1, 0x10, 0x06, 0)), 0)
Wait For TT_RunAsync (Flag As Int, Success As Boolean, Result As Object)
Log(Success)
TagTech.RunAsync("TT", "transceive", Array(Array As Byte(0xA2, 0x04, 0x03, 0x00, 0xFE, 0)), 0)
Wait For TT_RunAsync (Flag As Int, Success As Boolean, Result As Object)
Log(Success)
TagTech.Close
I'm not familiar with this structure. Just copied it from the answer.
Note that you need to use android.nfc.tech.NfcA instead of android.nfc.tech.NdefFormatable.