Android Question Problem with PhoneEvents

InfiniteImp

Member
Licensed User
I'm having a problem with PhoneEvents in that I can't get PhoneStateChanged and SMSDelivered to fire. The only event which fires is SmsSentStatus. I've tried everything I could think of to get the first two to fire. My understanding is that PhoneStateChanged should trigger as needed depending on what's going on with the phone and SMSDelivered when the recipient actually receives the message.

Out of those two, the second one is the one I actually care about. I put in the PhoneStateChanged just to test if PhoneEvents was working.


The code looks something like this. It's in a service module.

Help would be appreciated.


B4X:
Sub Process_Globals
    ...
    Dim PE As PhoneEvents
    Dim PhoneId As PhoneId
    ...
End Sub


Sub Service_Create
    ...
    PE.InitializeWithPhoneState("PhEvents", PhoneId)[/INDENT]
End Sub


Sub <ForDemonstrationOnly>
    ...
    Dim Ph As PhoneSms
    Ph.Send2(strCellNumber,strMessage,True,True)
    ...
End Sub


Sub PhEvents_SmsSentStatus(Success As Boolean, ErrorMessage As String, PhoneNumber As String, Intent As Intent)
    'LogStatus("----Send")
    If(Success) Then
        LogStatus("SMS Sent successfully")[/INDENT]
    Else
        LogStatus("SMS Send error.  Phone # '" & PhoneNumber & "', Error message: '" & ErrorMessage & "'")
    
        ProcessSMSResponse(PhoneNumber,ErrorMessage,True)[/INDENT]
    End If
End Sub


Sub PhEvents_SmsDelivered (PhoneNumber As String, Intent As Intent)
    LogStatus("----Delivered")
    LogStatus("SMS delivered to Phone # '" & PhoneNumber & "'")
    CallSub2(Main,"AddProgress","SMS delivered to Phone # '" & PhoneNumber & "'")
End Sub


Sub PhEvents_PhoneStateChanged (State As String, IncomingNumber As String, Intent As Intent)
    LogStatus("PhoneStateChanged to '" & State & "'")
    CallSub2(Main,"AddProgress","PhoneStateChanged to '" & State & "'")[/INDENT]
End Sub
 
Last edited:

KMatle

Expert
Licensed User
SmsDelivered

I think "delivered" depends on the provider. Mine doesn't send back a message, so the event isn't fired.

PhoneStateChanged

Did you try on another device? Did you set all permissions? Did you add it to the whitelist (protected apps if it's a Huwawei phone). If your code is in the starter service, move it to another (new) service and retry.
 
Upvote 0

InfiniteImp

Member
Licensed User
You could be right about the Delivered. No, I didn't try it on another service. Currently I have it in its own service, not Starter. I'll try creating a service for the PhoneStateChanged and see what happens. Not familiar with the whitelist but I did exclude the app from any powersaving features but not sure where I'd whitelist it (running on a Samsung Galaxy S6)
 
Upvote 0
Top