Hi all,
I read most of the threads about PSC but I can't still make it work for me.
My code looks like the following:
What it should do is simply to mute the ringing for the default telephony app and then un-mute it if it intercepts the ringing status.
Now, everything in service create works as expected, so when calling my device I get the default telephony app to come to foreground, shows an incoming call along with the callig number BUT silenced.
What doesn't work is that the PhoneStatusChanged event is never called so the service can take no action on it.
Correct me if I am wrong, but using PhoneEvents in a service along with Service.StartForeround is an alternative to have an intent filter in the manifest (dynamic vs. static); the benefit of using this approach should be that I can start/stop the service at will comanding when the interception of broadcasts should go on on/off.
Do you think there's the possibility that my device's default telephony app runs the same RINGING interceptor to a very high priority so to be the first to receive it and then one "consuming" it, so nothing is left to my service? If yes, how can I discover it and how can I circumvent it?
Umberto
I read most of the threads about PSC but I can't still make it work for me.
My code looks like the following:
B4X:
' in a toggle button event as part of Main
Sub btnDND_CheckedChange(Checked As Boolean)
If Checked Then
StartService(svc_dnd)
Else
StopService(svc_dnd)
End If
End Sub
'Service module: svc_dnd
Sub Process_Globals
Dim PhoneId As PhoneId
Dim PE As PhoneEvents
Dim p As Phone
Dim sNotif As Notification
End Sub
Sub Service_Create
PE.InitializeWithPhoneState("PE", PhoneId)
p.SetMute(p.VOLUME_RING,True)
sNotif.Initialize
sNotif.Icon = "icon"
sNotif.SetInfo("DND","Service Running",Main)
sNotif.Sound = False
sNotif.Vibrate = False
sNotif.Notify(1)
Service.StartForeground(1,sNotif) 'ok notification fires
End Sub
Sub Service_Start(StartingIntent As Intent)
Log("start: "&StartingIntent) 'ok this one fires
End Sub
Sub Service_Destroy
PE.StopListening 'used when I call StopService from main
End Sub
Sub PE_PhoneStatusChanged(State As String, IncomingNumber As String, Intent As Intent)
Log("status: "&State) 'NO. it never fires!!
Log("number: "&IncomingNumber)
Log("intent: "&Intent)
If State ="RINGING" Then
Log("ringing") 'NO. never fires
p.SetMute(p.VOLUME_RING,False)
End If
End Sub
What it should do is simply to mute the ringing for the default telephony app and then un-mute it if it intercepts the ringing status.
Now, everything in service create works as expected, so when calling my device I get the default telephony app to come to foreground, shows an incoming call along with the callig number BUT silenced.
What doesn't work is that the PhoneStatusChanged event is never called so the service can take no action on it.
Correct me if I am wrong, but using PhoneEvents in a service along with Service.StartForeround is an alternative to have an intent filter in the manifest (dynamic vs. static); the benefit of using this approach should be that I can start/stop the service at will comanding when the interception of broadcasts should go on on/off.
Do you think there's the possibility that my device's default telephony app runs the same RINGING interceptor to a very high priority so to be the first to receive it and then one "consuming" it, so nothing is left to my service? If yes, how can I discover it and how can I circumvent it?
Umberto