Hello everyone, I would add in my program, the ability to receive messages even when the app is in the background, is expected to play an audio file for each message received, to receive messages using my personal web site with FTP sending a text file. txt and receiving message using http with a timer set every 4 seconds that updates the label lblMessage in case of new messages, how do I get sound from the audio file whenever a new message when the program is in the background?
someone can create an example?
thanks
someone can create an example?
thanks
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 timer1 As Timer
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 txtmessagerx As EditText
Dim lblmessage As Label
Dim mp As MediaPlayer
Dim btnsend As Button
Dim txttext As EditText
Dim ftp1 As FTP
Dim txtwriter As TextWriter
Dim p As Phone
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("assistente")
timer1.Initialize("timer1",4000)
timer1.Enabled=True
txtmessagerx.Visible=False
req.InitializeGet("http://www.example.com/message/bottle.txt") '<--- Replace this with your info
hc.Execute(req, 1)
End Sub
Sub timer1_Tick
hc.Execute(req, 1)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub hc_ResponseSuccess(Response As HttpResponse, TaskId As Int)
txtmessagerx.text = Response.GetString("UTF8")
lblmessage.text=txtmessagerx.text
End Sub
Sub txtmessagerx_TextChanged (Old As String, New As String)
If txtmessagerx.text = Old Then
Else
sound
End If
End Sub
Sub sound
mp.Initialize
mp.Load(File.DirAssets,"ding.wav")
mp.Play
End Sub
Sub btnsend_Click
txtwriter.Initialize(File.OpenOutput(File.DirInternal, "bottle.txt" , False))
txtwriter.Write(txttext.text)
ftp1.Initialize("ftp1","ftp.example.com",21,"example","example")
txtwriter.Close
ftp1.SendCommand("MKD","/message")
ftp1.UploadFile(File.DirInternal,"bottle.txt",True,"/message/bottle.txt")
ftp1.Close
txttext.text=""
ToastMessageShow("Messagge send",True)
p.HideKeyboard(Activity)
End Sub
Last edited: