Please Help "PhoneStateChanged"

SoyEli

Active Member
Licensed User
Longtime User
Hello :)

Can someone pleeeeease show me a sample CODE for:
showing the phoneEvents using a textbox

Example: if the phone rings, the textbox would show "event & phone number"

I can not find any examples :sign0085:

Thank you:
SoyEli
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
In a service module:

B4X:
'Service module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   
   Dim PE As PhoneEvents
   Dim strNumber As String
        Dim strState As String


End Sub
Sub Service_Create
   PE.Initialize("PE")
   
End Sub

Sub Service_Start

End Sub

Sub Service_Destroy

End Sub

Sub PE_PhoneStateChanged (State As String, IncomingNumber As String, Intent1 As Intent)
strNumber = IncomingNumber
strState = State

'State - One of the three values: IDLE, OFFHOOK, RINGING. OFFHOOK means that there is a call or that the phone is dialing.

 'Then something like:

If strState = "RINGING" then
msgbox(strNumber,"Phonenumber")

End if
End Sub

Read here for more info:
http://www.b4x.com/android/help/phone.html#phoneevents

XverhelstX
 
Upvote 0

SoyEli

Active Member
Licensed User
Longtime User
PhoneEvents

Hello

Only the regular screen shows up.
I have the "USB Debugging" checked
Am I missing some kind of setting on the phone ?

Thank you:
 
Upvote 0

SoyEli

Active Member
Licensed User
Longtime User
PhoneEvents

Hello :confused:

startservice("service name")?
Sorry I'm new
did a search for startservice, with no example

can you explain?

Thank you:
 
Upvote 0

SoyEli

Active Member
Licensed User
Longtime User
Thank you:

Thats what I have been doing, trying to find info

When the phone rings it acts like it terminates the app, then after I hang up
the phone its looking for the debugger, finds it and reconnects.

I'll read everything that I need to, just point me to it.

Thank you :)
 
Upvote 0

SoyEli

Active Member
Licensed User
Longtime User
PhoneEvents

I checked out "Basic4android Tutorials pdf" with no luck
I was looking for a sample HOW to use the "startservice"
Looked for "Startservice" did not understand it.

startservice(name of app, or "PE" phoneEvents) ???
this goes in the " Sub Service_Start " ???

Thank you:
 
Upvote 0

XverhelstX

Well-Known Member
Licensed User
Longtime User
Upvote 0

SoyEli

Active Member
Licensed User
Longtime User
Help With startservice

Hello:

I did that "Startservice(interceptor)" in activity,Sub PE_PhoneStateChanged (, even with a button with no luck

by the way is the "interceptor" the "app name" or the "PE" As PhoneEvents ?
and where does it go ?

Phone runs the app but when phone rings app goes away and regular screen comes up, after hangup phone finds debugger and load app.
maybe thats the problam.
here it is:

Thank you for your HELP :)

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim PE As PhoneEvents
Dim strNumber As String
Dim strState As String
End Sub
Sub Service_Create

End Sub
Sub Service_Start

End Sub
Sub Service_Destroy

End Sub

Sub PE_PhoneStateChanged (State As String, IncomingNumber As String, Intent1 As Intent)
strNumber = IncomingNumber
strState = State
'State - One of the three values: IDLE, OFFHOOK, RINGING. OFFHOOK means that there is a call or that the phone is dialing.

'Then something like:
If strState = "RINGING" Then
EditText1.Text = strNumber
End If
If strState = "IDLE" Then
EditText1.Text = "IDLE"
End If
If strState = "OFFHOOK" Then
EditText1.Text = "OFFHOOK"
End If
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.

Dim EditText1 As EditText
Dim Panel1 As Panel
Dim Button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Caller")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub Button1_Click()
StartService("PE")
End Sub
 
Upvote 0
Top