If you want to trigger an action when a call is received, I suggest you do this:
-If you are waiting for a call that needs to be answered, use telephone.call_state(callback_function) to wait for a change in the phone's status, and if that change is that the call is connected, perform the action.
-The same applies for a call that isn't necessarily answered, just that the new state isn't "connected", it's "ringing".
Examples will help you understand better.
For the answered incoming call:
Code:
import telephone, e32, appuifw, logs
def quit():a.signal()
appuifw.app.exit_key_handler=quit
def handle_incoming_call(state):print "incoming call answered"
def cb(state):
if(state[0]==telephone.EStatusConnected):
if(float(logs.calls(mode='in')[0]["time"])>float(logs.calls(mode='out')[0]["time"])):handle_incoming_call(state)
'''You have to check the logs in order to see if the most recent call was incoming or outgoing
as EStatusConnected is for both'''
telephone.call_state(cb)
a=e32.Ao_lock()
a.wait()
For the ringing incoming call:
Code:
import telephone, e32, appuifw, logs
def quit():a.signal()
appuifw.app.exit_key_handler=quit
def handle_incoming_call(state):print "incoming call ringing"
def cb(state):
if(state[0]==telephone.EStatusRinging):handle_incoming_call(state)
telephone.call_state(cb)
a=e32.Ao_lock()
a.wait()