Italian Mp3 e chiamata in arrivo

Giusy

Active Member
Licensed User
Salve a tutti,
Testando la mia app mi sono accorta che, mentre suona un mp3 ed arriva una chiamata, rispondendo continuo a sentire sia mp3 che la voce del chiamante.
Come posso intercettare la chiamata in arrivo ed interrompere "play"?
Grazie
 

Giusy

Active Member
Licensed User
Ciao @LucaMs, ho inserito queste istruzioni e la mia app ha lanciato un grido di dolore.
B4X:
Dim PhoneId As PhoneId
Dim PE As PhoneEvents
PE.InitializeWithPhoneState("PE", PhoneId)  'sottolineato in violetto

Sub PE_PhoneStateChanged (State As String, IncomingNumber As String, Intent As Intent)
    If State = "RINGING" Then
    '....   
    End If
End Sub

Aiuto
 

LucaMs

Expert
Licensed User
Longtime User
Ho provato, inserendo il tuo stesso codice nel modulo di servizio Starter e funziona:

B4X:
Sub Process_Globals
   Private PhoneId As PhoneId
   Private PE As PhoneEvents
End Sub

Sub Service_Create
   PE.InitializeWithPhoneState("PE", PhoneId)
End Sub

Sub Service_Destroy
   PE.StopListening
End Sub

Sub PE_PhoneStateChanged (State As String, IncomingNumber As String, Intent As Intent)
   Log("State: " & State)
   Log("Num  : " & IncomingNumber)
   If IncomingNumber = "123456789* Then
        CallSubDelayed(NomeDellaActivityCheContieneIlPlayer, "StopPlaying")
   End If
End Sub

Non so perché a te no; qualche incompatibilità con altro codice?

Comunque vale la pena mettere il codice nello Starter. Dovendo poi fermare il player, puoi chiamare una routine del modulo in cui esso è stato dichiarato, ad esempio:

CallSubDelayed(NomeDellaActivityCheContieneIlPlayer, "StopPlaying")

e fermare il player nella Sub StopPlaying.
 

Giusy

Active Member
Licensed User
Come da tuo suggerimento ho sostituito PhoneID con mPhoneID
B4X:
Dim mPhoneId As PhoneId
Dim PE As PhoneEvents

'in activity create
PE.InitializeWithPhoneState("PE", mPhoneId)


Sub PE_PhoneStateChanged (State As String, IncomingNumber As String, Intent As Intent)
    If State = "RINGING" Then
      if sp.isplaying then
              bottonepausa_click   
    End If
End Sub
Funziona alla perfezione. Posso lasciare tutto così senza usare starter vero?
(Funzionerà allo stesso modo con B4I?)
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…