PhoneEvents problems? (SmsSentStatus)

boten

Active Member
Licensed User
Longtime User
I'm having problems using the PhoneEvents object. I have an activity and a service module.

A1) When a button is pressed in the main activity - the service is started

S1) When the service starts, it initialize PhoneEvent to monitor sending SMS then calls "Do_Send" in main

A2) Do_Send send the sms (which the service should "capture")

S2) when the SmsSentStatus event fires, it updates some global vars and calls "smsfollow" in main

A3) smsfollow displays msgbox, stops the service and finish the activity.

As it happens, the SMS is sent, but SmsSentStatus seems not to be fired.

Attached is the project.
 

Attachments

  • phn.zip
    5.7 KB · Views: 347

boten

Active Member
Licensed User
Longtime User
Toast didn't help. The _SmsSentStatus never fired as there's nothing on the log from the event sub.
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Looking at your code, it seems like the service has just died away.
It processes Service_Create and Service_Start, and then it has nothing else to do, so it probably gets destroyed.
Is it getting destroyed?
...sorry for asking questions, im not at my computer otherwise i would check myself
 
Upvote 0

boten

Active Member
Licensed User
Longtime User
pls explain.
I pressed the back key after a very long wait for the service to do it's job (and fire the _SmsDelivered event). Only after a few minutes, when there's nothing on the log from the event, and needless to say, loooong after the SMS was received at the other phone, did I quit the app by the back key, thus destroying the service.

Shouldn't the service fire the _SmsDelivered event (and put something on the log) once the SMS is sent?
 
Upvote 0

boten

Active Member
Licensed User
Longtime User
I don't "care" about the SmsDelivered for now (no sub for it). What I'm worried is that the SmsSentStatus NEVER fires, even when the activity (and thus the service is working) is in foreground. The Log stmts in the SmsSentStatus do NOT produce any log output, also no log is produced from sub smsfollow (in main) which is called from the SmsSentStatus event sub.
When and how is SmsSentStatus fired?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is what I got when I ran your program:
B4X:
** Activity (main) Create, isFirst = true **

** Activity (main) Resume **
** Service (smsmod) Create *
service created
** Service (smsmod) Start **
service start
service event 0123456789===OK...true
service event, delivered=1
smsfollow
going to stop service....
** Service (smsmod) Destroy **
service destroy
** Activity (main) Pause, UserClosed = true **
Make sure that the phone library version is 1.60.
 
Upvote 0

boten

Active Member
Licensed User
Longtime User
note: Yesterday got the problems (b4a 1.6, phone 1.55), Today worked (b4a 1.7, phone 1.6) :)

I got SmsSentStatus to work, but:

I call smsmsg.Send twice in a loop with 2 different phone numbers in the main activity
B4X:
Dim smsmsg As PhoneSms
Dim i As Int
For i=0 To telmap.Size-1
  smsmsg.Send(telmap.GetValueAt(i),mymsg)
  Log("do send to " & telmap.GetValueAt(i))
Next


in the service I have:
B4X:
Sub zzz_SmsSentStatus(Success As Boolean, ErrorMessage As String, PhoneNumber As String, Intent As Intent)
Log("service event " & PhoneNumber & "===" & ErrorMessage & "..." & Success)
CallSub(main,"smsfollow")
End Sub

the log shows that the service event is called twice BUT with the same number (2nd number)
B4X:
do send to 11111111  <=== changed for posting here
do send to 22222222  <=== changed for posting here

service event 22222222===OK...true
service event 22222222===OK...true

The sms is sent to the 2 different numbers.
 
Last edited:
Upvote 0

boten

Active Member
Licensed User
Longtime User
phone 1.6 seems to do the trick, event fired!

...
You will need to wait for the first message to be sent and then send the second one. Otherwise you will only get the status of the last sent message.
Ok, gotcha, thx
 
Upvote 0

boten

Active Member
Licensed User
Longtime User
sending the SMSs one-by-one and waiting for the event works fine, thx.

Another question on the subject:
B4X:
Dim c As PhoneCalls
Dim s As PhoneSms
StartActivity(c.Call("0123456789"))
s.Send("0123456789","hello there")

the phone call is shown later on the phone's call log, but there's no sign of the SMS sent in "messaging" application, why?
 
Upvote 0
D

Deleted member 103

Guest
Hi boten,

sending the SMSs one-by-one and waiting for the event works fine, thx.

Erel wrote:
You should call Service.StartForeground to prevent it from being destroyed.

I do not know how it works, how you did it?

Ciao,
Filippo
 
Upvote 0

cmweb

Active Member
Licensed User
Longtime User
sending the SMSs one-by-one and waiting for the event works fine, thx.
Could please someone explain, how to do that?

For example, the app has to send 3 SMS to three different phone numbers.

After sending the first, how can I manage that the app waits for the SMSsent event before continuing with the next SMS send job?

Thanks,

Carsten
 
Upvote 0

cmweb

Active Member
Licensed User
Longtime User
Erel,

Thanks, that will help!

Best regards,

Carsten

Gesendet von meinem GT-N7000 mit Tapatalk
 
Upvote 0
Top