I am trying to read an health insurance card.
I read many post in the forum before writing.
TagTech_Connected give success=true
but ReadIsoDep_RunAsync give success=false
B4A v9.30
JavaObject v2.05
NFC v2.01
Am I on the right way or not?
I read many post in the forum before writing.
B4X:
Sub Process_Globals
Private prevIntent As Intent
End Sub
Sub Globals
Private nfc As NFC
Private TagTech As TagTechnology
Private ListView1 As ListView
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
ListView1.SingleLineLayout.Label.TextSize = 15
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)
'in this case we are only accessing Ndef tags.
If techs.IndexOf("android.nfc.tech.IsoDep") > -1 Then
''TagTech.Initialize("TagTech", "android.nfc.tech.NfcB" , si)
TagTech.Initialize("TagTech", "android.nfc.tech.IsoDep", si)
TagTech.Connect
ToastMessageShow("IsoDep",True)
End If
End If
End Sub
Private Sub Format_RunAsync (Flag As Int, Success As Boolean, Result As Object)
Log($"Writing completed. Success=${Success}, Flag=${Flag}"$)
End Sub
Private Sub TagTech_Connected (Success As Boolean)
'ToastMessageShow($"Connected: ${Success}"$,"")
Msgbox(Success,"")
If Success = False Then
ToastMessageShow("Error connecting to tag", True)
Log(LastException)
Else
ReadIsoDep
End If
End Sub
Private Sub ReadIsoDep
TagTech.RunAsync("ReadIsoDep", "transceive", Array(Array As Byte(0xA2, 0x03, 0xE1, 0x10, 0x06, 0)), 0)
'TagTech.RunAsync("ReadIsoDep", "getNdefMessage", Null, 0)
End Sub
Private Sub ReadIsoDep_RunAsync (Flag As Int, Success As Boolean, Result As Object)
ToastMessageShow("Reading completed. Success=" & Success & "," & "Flag=" & Flag,True)
ListView1.Clear
If Success Then
If Result = Null Then
ToastMessageShow("No records found.", False)
Else
Dim message As JavaObject = Result
Dim records() As Object = message.RunMethod("getRecords", Null)
For Each r As NdefRecord In records
ListView1.AddSingleLine(r.GetAsTextType)
Next
End If
End If
End Sub
Sub Activity_Pause (UserClosed As Boolean)
nfc.DisableForegroundDispatch
End Sub
B4X:
AddActivityText(Main,
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED"/>
</intent-filter>
<meta-data android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="@xml/nfc_tech_filter" />)
CreateResource(xml, nfc_tech_filter.xml,
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<tech-list>
<tech>android.nfc.tech.IsoDep</tech>
</tech-list>
</resources>)
TagTech_Connected give success=true
but ReadIsoDep_RunAsync give success=false
B4A v9.30
JavaObject v2.05
NFC v2.01
Am I on the right way or not?