Import is used to import a contact to a contacts database. The information must be imported from a VCard file. This API can be called both in synchronous and asynchronous mode.
The following is an example for using Import:
Asynchronous
event_id = contacts_handle.call('Import', {'Type': u'Contact','Data':{'SourceFile':u'c:\\Data\\python\\VCARD.txt'}},callback=get_import)
where, get_import is a user defined callback function.
The following table summarizes the specification of Import:
| Interface | IDataSource |
| Operation | Imports contact to the specified contacts database. |
| Response Model | Asynchronous and synchronous for Third Edition FP2 and Fifth Edition devices. Synchronous for Third Edition and Third Edition FP1 devices. |
| Pre-condition | IDataSource interface is loaded. |
| Post-condition | Updates database with imported contact. |
Input Parameters
Input parameter specifies the contact to import and optionally the target database.
|
Example of vcard format:
BEGIN:VCARD VERSION:2.1 N:Kent; Clark FN:Clark Kent ORG:Superman Inc. TITLE:Super Man TEL;WORK:VOICE:(111) 556-9898 TEL;HOME;VOICE:(090) 556-6767 ADR;WORK:;;3rd Rock from Sun;Solar System;Milky Way LABEL;WORK;ENCODING=QUOTED-PRINTABLE:3rd Rock from Sun=0D=0ASolar System=0D=0AMilky Way ADR;HOME:;;Krypton LABEL;HOME;ENCODING=QUOTED-PRINTABLE:Krypton EMAIL;PREF;INTERNET:clarkkent@krypton.com REV:2008042T195243Z END:VCARD
The output is an object, which contains ErrorCode and an ErrorMessage if the operation fails.
|
Errors
The following table lists the errors and their values:
|
Error Messages
The following table lists the error messages and their description:
|
Example
The following sample code illustrates how to import contacts from a VCard format file:
import scriptext
import e32
# Using e32.Ao_lock() to make main function wait till callback is hit
lock = e32.Ao_lock()
# Callback function will be called when the requested service is complete
def get_import(trans_id, event_id, input_params):
if event_id != scriptext.EventCompleted:
# Check the event status
print "Error in retrieving required info"
print "Error code is: " + str(input_params["ReturnValue"]["ErrorCode"])
if "ErrorMessage" in input_params["ReturnValue"]:
print "Error message:" + input_params["ReturnValue"]["ErrorMessage"]
else:
print "The contacts are imported"
lock.signal()
# Load contacts module
contacts_handle = scriptext.load("Service.Contact", "IDataSource")
event_id = contacts_handle.call('Import', {
'Type': u'Contact',
'Data':{'SourceFile': u'c:\\Data\\python\\VCARD.txt'}}, callback=get_import)
print "Waiting for the request to be processed!"
lock.wait()
print "Request complete!"
See About this document... for information on suggesting changes.