#Region Service Attributes
#StartAtBoot: False
#End Region
Sub Process_Globals
Dim audioManager As JavaObject
Public recoder As AudioStreamer
Dim listo As List
End Sub
Sub Service_Create
End Sub
Sub Service_Start (StartingIntent As Intent)
Service.StartForeground(1, CreateNotification("..."))
recoder.Initialize("recoder",22050,True,16,recoder.VOLUME_MUSIC)
recoder.StartRecording
listo.Initialize
listo.Clear
End Sub
Sub Service_Destroy
Dim r As Reflector
r.Target = recoder
r.Target = r.GetField("audioRecord")
r.RunMethod("release")
StartServiceAt(Me, DateTime.Now + 20 * DateTime.TicksPerSecond, True)
End Sub
Sub CreateNotification (Body As String) As Notification
Dim notification As Notification
notification.Initialize2(notification.IMPORTANCE_LOW)
notification.Icon = "icon"
notification.SetInfo("Calling", Body, Main)
Return notification
End Sub
Sub call_wait(c As Boolean)
If c = True Then
recoder.StopRecording
Else
recoder.StartRecording
End If
End Sub
Sub audio_Event (MethodName As String, Args() As Object) As Object
Try
If Args(0).As(Int)=-2 Then
call_wait(True)
Else if Args(0).As(Int)=-1 Then
call_wait(True)
else if Args(0).As(Int)=1 Then
call_wait(False)
End If
Catch
End Try
Return Null
End Sub
Sub recoder_RecordBuffer (Data() As Byte)
Private b As B4XSerializator
If listo.IsInitialized Then listo.Add(b.ConvertObjectToBytes(Data))
End Sub