In Symbian OS, the phone book is operated and managed through a default database (contacts. CDB. Therefore, in the Symbian system, you can use the contacts model API to access and manage the phone book. Here, the main class is ccontactdatabase (Database Class, set of all the phone books ), ccontactitem (which represents a separate phone book entry, identified by a unique tcontactitemid. For example, a contact in a phone book), ccontactitemfield (domain class, each phone book entry has many classes, such as Name Domain (epbkfieldidfirstname, epbkfieldidlastname), telephone number domain (epbkfieldidphonenumbergeneral )...).
The series60 developer has extended this model and used the "Phone Book engine". Below are several key classes.
Class cpbkcontactengine
The telephone book engine is implemented through cpbkcontactengine. If a default database already exists, cpbkcontactengine: newl () is connected to the database. Otherwise, the database is created.
Class cpbkcontactitem
The cpbkcontactitem class represents a specific entry in the phone book database, such as a contact. It provides access and search functions for the tpbkcontactitemfield array.
Class tpbkcontactitemfield
Tpbkcontactitemfield is the domain class of a thin phone entry, such as someone's telephone domain or someone's email.
// For more information about the phone book engine, see the SDK help.
// Haha, I will post a piece of code for accessing the phone book below. I hope you can correct it more.
Void cphoneengine: displaycontactinfol (mobjectprovider * amopparent)
{
Rpbkviewresourcefile phonebookresource (* (ceikonenv: static ()));
If (! Phonebookresource. isopen ())
{
Phonebookresource. openl ();
}
// Add searching array to parameters
Ccontactdatabase: tcontactviewfilter filter (ccontactdatabase: ephonable );
Cpbkmultipleentryfetchdlg: tparams Params;
Params. icontactview = & ipbkcontactengine-> filteredcontactsviewl (filter );
// Launch fetching Dialog
Cpbkmultipleentryfetchdlg * fetchdlg = cpbkmultipleentryfetchdlg: newl (Params, * ipbkcontactengine );
Fetchdlg-> setmopparent (amopparent );
Tint okpressed = fetchdlg-> executeld ();
Cleanupstack: pushl (Params. imarkedentries );
If (okpressed)
{
// Get the first selected contacts ID Array
Const tcontactitemid cid = (* Params. imarkedentries) [0];
// Open the selected contact using phonebook engine,
Cpbkcontactitem * pbkitem = ipbkcontactengine-> readcontactlc (CID );
// Get the first name
Tpbkcontactitemfield * fnamefield = pbkitem-> findfield (epbkfieldidfirstname );
Fnamefield-> gettextl (ifirstname );
// Get the last name
Tpbkcontactitemfield * lnamefield = pbkitem-> findfield (epbkfieldidlastname );
Lnamefield-> gettextl (ilastname );
// Get the general phonenumber
Tpbkcontactitemfield * phonefieldgeneral = pbkitem-> findfield (epbkfieldidphonenumbergeneral );
Phonefieldgeneral-> gettextl (inumbergeneral );
// Get the mobile phonenumber
Tpbkcontactitemfield * phonefieldmobile = pbkitem-> findfield (epbkfieldidphonenumbermobile );
Phonefieldmobile-> gettextl (inumbermoblie );
// Get the email address
Tbuf <30> emailaddress;
Tpbkcontactitemfield * emailfield = pbkitem-> findfield (epbkfieldidemailaddress );
Emailfield-> gettextl (emailaddress );
// Add codes to get other fields you interested in
//......
Cleanupstack: popanddestroy (pbkitem); // pbkitem, emailadd
}
// Release the resource
Cleanupstack: popanddestroy (); // imarkedentries
Phonebookresource. Close (); // close the phonebook View
}
// Note: Please indicate the source of the post or reference the above content!