PyMaemo/Phone call and SMS examples

Image:Ambox_notice.png
Please be aware that the recommended way to use the phone functionality is Telepathy:


[edit] SMS

  • Method calls:
    • Method: Send
      • Description: Use method to send messages
      • Parameters: (string, string) - (message, )
      • Interface: com.nokia.csd.SMS.Outgoing
      • Path: /com/nokia/phone/SMS/ba212ae1
      • Destination: com.nokia.phone.SMS
    • Code: Python
import dbus
bus = dbus.SystemBus()
smsobject = bus.get_object('com.nokia.phone.SMS', '/com/nokia/phone/SMS/ba212ae1')
smsiface = dbus.Interface(smsobject, 'com.nokia.csd.SMS.Outgoing')
arr = dbus.Array(pdu_array)
msg = dbus.Array([arr]) 
smsiface.Send(msg,'')
  • Signals:
    • Signal name: IncomingSegment
      • Description: Can be used to listen to incoming messages
      • Callback Parameters: (string, string, string, string)
      • Interface: Phone.SMS
      • Path: /com/nokia/phone/SMS
    • Code: Python
import gobject, dbus
from dbus.mainloop.glib import DBusGMainLoop
 
def handle_sms(pdu, msgcenter, somestring, sendernumber):
    print 'New message from %s' % sendernumber
 
DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
bus.add_signal_receiver(handle_sms, path='/com/nokia/phone/SMS',   dbus_interface='Phone.SMS', signal_name='IncomingSegment')
gobject.MainLoop().run()

[edit] Call

  • Method calls:
    • Method: Release
      • Description: Reject call
      • Parameters: ()
      • Interface: com.nokia.csd.Call.Instance
      • Path: /com/nokia/csd/call/1
      • Destination: com.nokia.csd.Call
    • Code: Python
bus = dbus.SystemBus()
callobject = bus.get_object('com.nokia.csd.Call', '/com/nokia/csd/call/1')
smsiface = dbus.Interface(callobject, 'com.nokia.csd.Call.Instance')
smsiface.Release()
    • Method: Answer
      • Description: Answer call
      • Parameters: ()
      • Interface: com.nokia.csd.Call.Instance
      • Path: /com/nokia/csd/call/1
      • Destination: com.nokia.csd.Call
    • Code: Python
# Just answer
bus = dbus.SystemBus()
callobject = bus.get_object('com.nokia.csd.Call', '/com/nokia/csd/call/1')
smsiface = dbus.Interface(callobject, 'com.nokia.csd.Call.Instance')
smsiface.Answer()
# Answer then hangup
import time
 
bus = dbus.SystemBus()
callobject = bus.get_object('com.nokia.csd.Call', '/com/nokia/csd/call/1')
smsiface = dbus.Interface(callobject, 'com.nokia.csd.Call.Instance')
smsiface.Answer()
time.sleep(0.5)    # wait 0.5 secs or 500 ms
smsiface.Release()
  • Signals:
    • Signal name: Coming
      • Description: Can be used to listen to incoming calls
      • Callback Parameters: (string, string) - (obj_path, callernumber)
      • Interface: com.nokia.csd.Call
      • Path: /com/nokia/csd/call
    • Code: Python
import gobject, dbus
from dbus.mainloop.glib import DBusGMainLoop
 
def handle_call(obj_path, callernumber):
    print '%s is calling' % callernumber
 
DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
bus.add_signal_receiver(handle_call, path='/com/nokia/csd/call', dbus_interface='com.nokia.csd.Call', signal_name='Coming')
gobject.MainLoop().run()