PyMaemo/Phone call and SMS examples
(use <source>) |
|||
(One intermediate revision not shown) | |||
Line 1: | Line 1: | ||
{{Recommended phone usage}} | {{Recommended phone usage}} | ||
- | |||
- | |||
== SMS == | == SMS == | ||
- | |||
*Method calls: | *Method calls: | ||
Line 14: | Line 11: | ||
***Destination: com.nokia.phone.SMS | ***Destination: com.nokia.phone.SMS | ||
**Code: Python | **Code: Python | ||
- | < | + | <source lang="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,'') | |
- | </ | + | </source> |
*Signals: | *Signals: | ||
Line 31: | Line 28: | ||
***Path: /com/nokia/phone/SMS | ***Path: /com/nokia/phone/SMS | ||
**Code: Python | **Code: Python | ||
- | < | + | <source lang="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() | |
- | + | </source> | |
- | + | ||
- | + | ||
- | </ | + | |
- | + | ||
== Call == | == Call == | ||
- | |||
*Method calls: | *Method calls: | ||
Line 56: | Line 51: | ||
***Destination: com.nokia.csd.Call | ***Destination: com.nokia.csd.Call | ||
**Code: Python | **Code: Python | ||
- | < | + | <source lang="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() | |
- | </ | + | </source> |
+ | |||
+ | **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 | ||
+ | <source lang="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() | ||
+ | </source> | ||
+ | |||
+ | <source lang="python"> | ||
+ | # 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() | ||
+ | </source> | ||
*Signals: | *Signals: | ||
Line 70: | Line 92: | ||
***Path: /com/nokia/csd/call | ***Path: /com/nokia/csd/call | ||
**Code: Python | **Code: Python | ||
- | < | + | <source lang="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() | |
- | + | </source> | |
- | + | ||
- | + | ||
- | </ | + | |
[[Category:Python]] | [[Category:Python]] |
Latest revision as of 10:28, 23 June 2010
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
- Method: Send
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
- Signal name: IncomingSegment
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
- Method: Release
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
- Method: Answer
# 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
- Signal name: Coming
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()
- This page was last modified on 23 June 2010, at 10:28.
- This page has been accessed 16,869 times.