sound file in service module

fifiddu70

Well-Known Member
Licensed User
Longtime User
Hello everyone, I would like to implement a program through the library http, this program must poll a web page every 4 seconds, check a text file txt, if the contents of the text file is changed, you should report it with a sound, the program must run in the background must not be active, I tried this, but I can not get the sound when the text file is changed.

B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   Dim hc As HttpClient
   Dim req As HttpRequest
   dim p as phone
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 timer1 As Timer   
   Dim lblmessage As Label
   Dim txtmessagerx As EditText
   Dim mp As MediaPlayer
      
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("message")
   p.SetScreenOrientation(1)
   mp.Initialize
   hc.Initialize("hc")
   timer1.Initialize("timer1",4000)
   timer1.Enabled=True
   req.InitializeGet("http://www.siciliabit.com/prova/messaggio.txt") 
   hc.Execute(req, 1)
      
End Sub

Sub timer1_Tick
   hc.Execute(req, 1)
End Sub


Sub hc_ResponseSuccess(Response As HttpResponse, TaskId As Int)
   txtmessagerx.Text = Response.GetString("UTF8")
   lblmessage.Text=txtmessagerx.Text
      
End Sub
Sub Activity_Resume
      
End Sub

Sub Activity_Pause (UserClosed As Boolean)
   StartService(hide)
   
End Sub

the service module
B4X:
#Region  Service Attributes 
   #StartAtBoot: False
#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 hc As HttpClient
   Dim req As HttpRequest
   Dim timer1 As Timer
   Dim mp As MediaPlayer
   
End Sub
Sub Service_Create
   hc.Initialize("hc")
   req.InitializeGet("http://www.siciliabit.com/prova/messaggio.txt") 
   timer1.Initialize("timer1",4000)
   
   timer1.Enabled=True
End Sub

Sub Service_Start (StartingIntent As Intent)
   timer1.Enabled=True
   hc.Execute(req, 1)
   
   StartServiceAt("", DateTime.Now + 0.1 * DateTime.TicksPerMinute, False)
   
End Sub
Sub timer1_Tick
   hc.Execute(req, 1)
End Sub
Sub Service_Destroy

End Sub
Sub hc_ResponseSuccess(Response As HttpResponse, TaskId As Int)
   ?????????????????????????   
End Sub

every 4 seconds, the program queries the web page, and if it's okay to be the result, as I play a file if the text within the txt file has changed?
 
Top