#Region  Service Attributes
    #StartAtBoot: False
    #StartCommandReturnValue: android.app.Service.START_STICKY
#End Region
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim PE As PhoneEvents
    Dim PhoneId As PhoneId
    Dim Path As String = File.DirRootExternal
    Dim Ar As AudioRecorder
   
    Dim Nt As Notification
End Sub
Sub Service_Create
    PE.InitializeWithPhoneState("PE", PhoneId)
   
    If File.Exists(Path,"RegCall")=False Then
        File.MakeDir(Path,"RegCall")
        Path=File.Combine(Path,"RegCall")
    End If
    Ar.Initialize()
    Ar.AudioSource = Ar.AS_VOICE_CALL
    'Ar.AudioSource = Ar.AS_MIC
    Ar.OutputFormat = Ar.OF_THREE_GPP
    Ar.AudioEncoder = Ar.AE_AMR_NB
   
    Nt.Initialize
    Nt.AutoCancel=False
    Nt.Icon="icon"
    Nt.SetInfo("CallRecorder","Wait",Main)
    Nt.Sound=False
    Nt.Vibrate=False
    Service.StartForeground(1,Nt)
End Sub
Sub Service_Start (StartingIntent As Intent)
End Sub
Sub Service_Destroy
End Sub
Sub PE_PhoneStateChanged (State As String, IncomingNumber As String, Intent1 As Intent)
    If State="RINGING" Then
        'Squillo
        If Ar.isRecording Then Ar.stop
        Dim FileName As String = DateTime.Now & ".wav"
        Log(Path & FileName)
        Ar.setOutputFile(Path,FileName)
        Ar.prepare()
    Else If State="OFFHOOK" Then
        'Sganciato
        Ar.start
    else If State="IDLE" Then
        'libero
       
    End If
End Sub