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}"$)
If techs.IndexOf("android.nfc.tech.NfcA") > -1 Then
TagTech.Initialize("TagTech", "android.nfc.tech.NfcA" , si)
'Get the UID
Dim jo As JavaObject = TagTech
Dim tag As JavaObject = jo.RunMethod("getTag", Null)
Dim rawId() As Byte = tag.RunMethod("getId", Null)
Dim bc As ByteConverter
Log(bc.HexFromBytes(rawId))
'Connect to the tag
TagTech.Connect
Else
ToastMessageShow("Tag does not support Ndef/NfcA/IsoDep...", True)
End If
End If
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
If rdbRead.Checked Then
'after connection
TagTech.RunAsync("TT", "transceive", Array(Array As Byte(0x90, 0x5A, 0x00, 0x00, 0x03, 0xC0, 0x8E, 0xF4, 0x00)), 0)
Wait For TT_RunAsync (Flag As Int, Success As Boolean, Result As Object)
Log(Success)
TagTech.RunAsync("TT", "transceive", Array(Array As Byte(0x90, 0xBD, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00)), 0)
Wait For TT_RunAsync (Flag As Int, Success As Boolean, Result As Object)
Log(Success)
TagTech.Close
Else
WriteNdef(Array(nfc.CreateMimeRecord("text/plain", flTxt1.Text.GetBytes("UTF8")), _
nfc.CreateMimeRecord("text/plain", flTxt2.Text.GetBytes("UTF8"))))
End If
End If
End Sub