1. In Main.b4a i have following:
2. In myService.bas i have following:
3. myService.bas is running as background service. But it is failing to call following:
4. When App is running in background CallSub(Main,"sendSMS") fails but when the app is
active CallSub(Main,"sendSMS") works.
Q. How to make the CallSub(Main,"sendSMS") method work from the background service?
B4X:
Sub sendSMS
Log(">>> JOB SMS: " & myService.sms_id)
If myService.working_on_sms = "" Then
myService.working_on_sms = myService.sms_id
Log(">>> JOB STARTED: " & myService.working_on_sms)
' Clear the SMS job
job2.Initialize("job2", Me)
Dim new_login As String = "id=" & myService.working_on_sms & "&action=done"
Dim new_loginurl As String = "https://" & myService.myAgentID & ".do not show.com/app/smssent"
job2.PostString(new_loginurl,new_login)
' SMS
Dim Sms1 As PhoneSms
Sms1.Send(myService.sms_to,myService.sms_text)
' WhatsAPP
'Dim Intent1 As Intent
'Intent1.Initialize(Intent1.ACTION_VIEW, $"https://api.whatsapp.com/send?phone=${myService.sms_to}&text=${myService.sms_text}"$)
'StartActivity(Intent1)
' Dial
'Dim skype As Intent
'"skype:echo123?call&video=true"
'skype.Initialize(skype.ACTION_VIEW, "skype:echo1234?chat&topic=skype_notify")
'skype.SetComponent("com.skype.raider")
'StartActivity(skype)
myService.working_on_sms = ""
Else
Log(">>> JOB BUSY: " & myService.working_on_sms)
End If
End Sub
2. In myService.bas i have following:
B4X:
Sub JobDone (Job As HttpJob)
Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
If Job.Success = True Then
Select Job.JobName
Case "job1"
'print the result to the logs
parser.Initialize(Job.GetString)
Dim root As Map = parser.NextObject
Dim result As String = root.Get("result")
Log(">>> HTTPS: " & result)
If result = "ok" Then
' Do the SMS task
sms_id = root.Get("sms_id")
sms_status = root.Get("sms_status")
sms_to = root.Get("sms_to")
sms_text = root.Get("sms_text")
If sms_status = "pending" Then
Log(">>> sendSMS call")
CallSub(Main,"sendSMS")
End If
' Do OLD activity
Dim db As List = root.Get("db")
CallSub(Main,"clearList")
For Each coldb As Map In db
'Dim kiosk As String = coldb.Get("username")
Dim callstatus As String = coldb.Get("callstatus")
Dim callername As String = coldb.Get("callername")
If callstatus = "orange" Then
html = callername
rowCallstatus = callstatus
CallSub(Main,"addList")
Notification1.Sound = True
Notification1.SetInfo("do not show: " & callername, "Agent: " & myUsername & ", " & "Ticking: " & myTicking , Main)
Notification1.AutoCancel = True
'Notification1.Notify(1)
Notification1.Vibrate = True
If IsPaused(Main) Then
'StartActivity("Main")
CallSub(Main, "SetShowWhenLocked")
StartActivity("Main")
Else
CallSub(Main, "SetShowWhenLocked")
StartActivity("Main")
End If
Else If callstatus = "red" Then
html = callername
rowCallstatus = callstatus
CallSub(Main,"addList")
Else
html = callername
rowCallstatus = callstatus
CallSub(Main,"addList")
End If
Next
CallSub(Main, "FinishDownload")
Else
Log("fail")
' Do the SMS task
sms_id = root.Get("sms_id")
sms_status = root.Get("sms_status")
sms_to = root.Get("sms_to")
sms_text = root.Get("sms_text")
If sms_status = "pending" Then
CallSub(Main,"sendSMS")
End If
End If
End Select
Else
Log("Error: " & Job.ErrorMessage)
End If
Job.Release
End Sub
3. myService.bas is running as background service. But it is failing to call following:
B4X:
CallSub(Main,"sendSMS")
4. When App is running in background CallSub(Main,"sendSMS") fails but when the app is
active CallSub(Main,"sendSMS") works.
Q. How to make the CallSub(Main,"sendSMS") method work from the background service?