Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim uManager As UsbManager
Dim uDevice As UsbDevice
' ************
' JAVA VARS
'*************
Dim mReader As JavaObject
Dim device As JavaObject
Dim Manager As JavaObject
Private Button1 As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("1")
verificaUsbDevice
NewReader ' Create new instance
CreateEvent ' Create an event
OpenReader ' open reader
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub NewReader As JavaObject
Private jo As JavaObject
Manager= GetContext.RunMethod("getSystemService", Array("usb"))
mReader=jo.InitializeNewInstance ("com.acs.smartcard.Reader",Array As Object (Manager))
End Sub
Sub CreateEvent As JavaObject
Private callback As Object
callback=mReader.CreateEvent ("com.acs.smartcard.Reader.OnStateChangeListener", "status", Null)
Private cObject As Object = mReader.RunMethod("setOnStateChangeListener",Array As Object (callback))
End Sub
Sub OpenReader As JavaObject
device=mReader.RunMethod ("open",Array (uDevice))
End Sub
Sub status_event(MethodName As String, Args() As Object) As Object
Private slotNum As Int=Args(0)
Private prevState As Int=Args(1)
Private currState As Int=Args(2)
Private getState As Object
Private Unknown As Int=mReader.GetField ("CARD_UNKNOWN")
Private Absent As Int =mReader.GetField ("CARD_ABSENT")
Private Present As Int =mReader.GetField ("CARD_PRESENT")
Private Undefined As Int=mReader.GetField ("PROTOCOL_UNDEFINED")
getState=mReader.RunMethod ("getState", Array As Object (slotNum))
If currState=Unknown Then
Msgbox("Card Unknown","Status")
End If
If prevState > currState AND currState<>Unknown Then
Msgbox ("Card Removed","Status")
Else
If currState<>Unknown Then
Msgbox ("Cartão Inserted","Status")
End If
End If
End Sub
Sub verificaUsbDevice As Object
uManager.Initialize
Dim usbdevices() As UsbDevice
usbdevices = uManager.GetDevices
For i = 0 To usbdevices.Length - 1
' Dim ud As UsbDevice
uDevice = usbdevices(i)
Next
If uManager.HasPermission(uDevice) = False Then
uManager.RequestPermission(uDevice)
End If
Return uDevice
End Sub
Sub Button1_Click
'CheckUSB2
End Sub
Sub GetContext As JavaObject
Return GetBA.GetField("context")
End Sub
Sub GetBA As JavaObject
Dim jo As JavaObject
Dim cls As String = Me
cls = cls.SubString("class ".Length)
jo.InitializeStatic(cls)
Return jo.GetFieldJO ("processBA")
End Sub