In the previous article, we introduced the operational methods of documents and directories. This article we discussed the use of communication in mobile phones.
First, in the file and directory articles, we introduce the system RAM mainly used for active programs and system kernels, and can be accessed as disk space C: disc. In fact, the data in the communication record is that there is a RAM that is provided by a wide variety of functions that operate these data.
Next, let's simplify the structure of the communication model, which is based on a communication database, and a database contains some communication records. Each communication record has some domains, such as name, address, and phone number, and more. A mobile phone may have several communication databases, but there will always be a default database. In the environment I work (S60 SDK 2.1) ../symbian/7.0s/series60_v21_c/epoc32/wins/c/system/data/contacts.cdb is the default database of the simulator. We know that there will often encounter issues related to the OBEX protocol in mobile application development. In fact, in the communication record development, it also follows this protocol, and the data in the communication record is a carrier called VCARD. VCARD is a type of electronic business card to get support for many electronic devices such as PDA and mobile phones. The purpose of VCARD is to deliver convenient communication data delivery between these devices. You can encode the VCARD into the coded text defined by the MIME specification (RFC 1521). This encoding ensures that the various VCARDs are fully compatible with the delivery coding of the 7-bit character set (such as encoding used in the SMS message). A vcard is formatted as follows: Begin: vcard version: 2.1 N: Wilkinson; Steve Fn: Steve Wilkinson Org: EMCC Software Ltd. Tel; Work; Voice: 01617779700 ADR; Work; Encoding = quoted-printable: ;; 108 manchester . Rd = 0D = 0ACarrington; Manchester; UK; M31 4BD; United Kingdom LABEL; WORK; ENCODING = QUOTED-PRINTABLE:. 108 Manchester Rd = 0D = 0ACarrington = 0D = 0AManchester, UK M31 4BD = 0D = 0AUnited K = ingdom EMAIL , PREF; Internet: steve.wilkinson@emccsoft.com REV: 20030909T164330 ZEND: Many of the features in the VCARD communication model are related to the processing of VCARD to ensure that Symbian application development partners can easily prepare electronic business cards and address book exchange. Industrial standard code.
Let's brief introduction to several classes before specific practice: CContactDatabase class is used to create a new database or open an existing database. It also provides the function of accessing the communication records. You can also read communication records can also be read. If you want to edit or delete the item, you must open it, although an app can only open a specific communication record at some point in time. When the modification of the communication record is completed, it is saved to the database. Of course, this class also provides a lot of other features, such as sort, lookup, and more. This class is a class that is important in communication.
The communication model provides the MContACTDBOBSERVER class, and an application can inherit from this class, which is used to receive a revised prompt generated by a particular communication database. Those applications that use this viewer (OBServer) receive event hints, which can be added to the database, modify, or delete an existing communication record, and other useful tips within a certain range. All communication records are inherited from abstract class CContactItem, and access to their access is managed by the CContactDatabase class. You can get the unique ID of each communication record with the ccontactItem :: ID () function (which returns a TContactItemID). The CContactItem class also includes functions that operate on the domain inside the communication record. You can add and insert a new domain or you can delete an existing domain in your project.
Some fields inside a communication record are represented by the CContactItemfield class. For convenience, all domains located inside a particular item are stored inside a structure, which is called a ccontactItemfieldset. Each communication recorder stores actual domain data and a specific storage type for this data. This can be a text string, a data / time value, a store, or a proxy, which is represented by the TSTORAGETYPE class. A proxy domain is basically a link to another communication. For example, Series 60 Platform is implemented: contacting other communication records to the communication recorder. Note: The communication recorded domain indicated here is not supported here. All digital information, such as phone numbers and fax numbers, are saved as text. Next, our practice will use the above class, so the above class needs to be careful, more details can also find the associated SDK's Help file.
Open, close the database ccontactDatabase :: OpenL () function has two overload functions. If the function does not give a parameter, open the default database. Another situation is that the application designer can also pass a path and file name about the database, which is set to open another database. ------------------------------------------ // Open the default Contacts Database . CContactDatabase * contactsDb = CContactDatabase :: OpenL (); // open the default database CleanupStack :: PushL (contactsDb);. // Count how many contacts are in the default database and then // delete the CContactDatabase object // Note that all Resources Owned by the Contacts Database Are Freed // Upon Deletion. Tint NumberOfContacts = ContactSDB-> countl (); // All data items Cleanupstack :: PopandDestroy (ContactSDB); // Destruction ---------- --------------------------------- To note that a communication database does not have a close () function Or similar functions.
The only difference between the new database ccontactDatabase :: Createl () function and ccontactDatabase :: ReplaceL () If the database already exists, the former will exit with KerraLReadyexists. As mentioned earlier, these functions will create a default database if the parameters are not defined. The ccontactDatabase :: FindContactFile () function gives a descriptor, and if there is no default database, the descriptor returns the location of the default database. ------------------------------------------ // if one is found, replace it with a new empty default database // if no default database is found, create a new one TFileName contactDbFilePath;.. CContactDatabase * newDefaultContactDb; if (CContactDatabase :: FindContactFile (contactDbFilePath)) // if there is a default database {newDefaultContactDb = CContactDatabase :: ReplaceL ();} else {newDefaultContactDb = CContactDatabase :: CreateL ();} CleanupStack :: PushL (newDefaultContactDb); // add their own function code CleanupStack :: PopAndDestroy (newDefaultContactDb); --------- ----------------------------------
Traversing communication records can be used to traverse a communication database with a TContactiter class. This class provides a complete set of functions for traversing all communication records. All functions are operated with a communication recorder ID (TContactItemID), which is used to access a particular communication record. ------------------------------------------ // Open the default Contacts Database : CcontactDatabase * ContactSDB = ccontactDatabase :: OpenL (); Cleanupstack :: Pushl (contactsdb); tcontactiter per (* contactsdb); // Similar cursor TContactItemid CardID;
While ((cardid = iter.nextl ())! = knullcontactid) // loop traverses {ccontactItem * card = contactsdb-> readcontactL (cardid); // Read Cleanupstack :: Pushl (Card);
// Add your own function code
ContactSDB-> CloseContactL ()); Cleanupstack :: PopandDestroy (); // card} Cleanupstack :: PopandDestroy (); // ContactsDB ---------------------------------------- ---------------------------
Export all communication items to files Mainly using the ExportSelectedContactsl function in class ccontactDatabase. S60 2.1help is defined as follows: ------------------------------------------- void ExportSelectedContactsL (const TUid & aFormat, const CContactIdArray & aSelectedContactIds, RWriteStream & aWriteStream, TInt aOption, TBool aExportPrivateFields = ETrue); void ExportSelectedContactsL (const TUid & aFormat, const CContactIdArray & aSelectedContactIds, RWriteStream & aWriteStream, TInt aOption, const CVersitParser :: TVersitCharSet aCharSet, TBool aExportPrivateFields = Etrue); Supported from 6.0
Description: Exports An Array Of Contact Items to a Write Stream - Overloaded Function. The items before.................
Parameters: const TUid & aFormat: Indicates the format for imported and exported contacts Must have a value of KVersitEntityUidVCard const CContactIdArray & aSelectedContactIds:.. Array of contact IDs to export RWriteStream & aWriteStream:. The stream to write to TInt aOption:. Indicates the options for import and export See the TOptions enum const CVersitParser :: TVersitCharSet aCharSet:... The character format If not specified, defaults to CVersitParser :: EUTF8CharSet TBool aExportPrivateFields = ETrue:.. ETrue exports fields marked as private EFalse does not export fields marked as private See ccontactItemfield :: setPrivate ().
Leave Codes: KerrNotsupported AFORMAT.IUID Is Not KversitityUidvcard.kerrnotfoundIndiD in The Contact Items Does Not Exist in The Database. ---------------------------------------------------------------------------------------------------------------------------- ------------------ routines are as follows: --------------------------- ---------------- RFS FileESession; user :: leaveiferror (filesession.connect ()); // Connect file server cleanupclosepushl (filession); ccontactDatabase * contactDb = ccontactDatabase :: OpenL ); // open the default database CleanupStack :: PushL (contactDb); CContactIdArray * exportContact = CContactIdArray :: NewL (); // array of recording data items CleanupStack :: PushL (exportContact); RFile file; file.Replace (fileSession, aFileName , Efilewrite; // New file, AFILENAME is file name cleanupclosepushl (file); RFileWritStream OutputStream (file); // Declare file stream CleanupClosepushl (OutputStream);
ExportContact = icontacts; // icontacts is an array that has initiated the corresponding export attribute, requires class ccntfilter // such as: // ccntfilter * filter = ccntfilter :: newlc (); // filter-> setContactFilTelTyPEAll (Efalse); // filter-> SetContactFilterTypeCard (ETrue); // exported in vCard format // contactDb-> FilterDatabaseL (* filter); // fetches the corresponding entry TUid id satisfies the condition of the filter in accordance with the attribute; id.iUid = KVersitEntityUidVCard; contactDb-> ExportSelectedContactsL (ID, * exportContact, // Export to File AWRITESTREAM, CCONTACTDATABASE :: EEXCLUDEUID; Cleanupstack :: PopandDestroy (5); ----------------------- --------------------
Deleting a Specified Communication Book You can use class cpbkcontactengine, which can be easily completed, which is equivalent to operating a quick engine operating mobile phone communication: cpbkcontactengine * ipbkcontactengine = cpbkcontactengine :: newl (); so it A engine object for a default communication record will be established. Then: ----------------------------------------- Import_c void cpbkcontactengine :: DeleteContactL (TContactItemId aContactId, TBool aImmediateNotify = EFalse) IMPORT_C void CPbkContactEngine :: DeleteContactsL (const CContactIdArray & aContactIds, TBool aImmediateNotify = EFalse) ----------------------- -------------------- The above two functions can complete the deletion operation, just one is a communication record that deletes a specific ID, the other is to delete one satisfaction Conditional communication recorder array. Simple call implementation: ipbkcontactengine-> deleteContactL (ID); IPBKContactengine-> compressL () after deletion; check the database under the compression of the database, because the compression is time consuming, so do not per delete.
Of course, there is a class CPBKContactengine, we can also achieve new and modify the functionality of the communication record. In fact, we can complete the same functionality at the beginning of the article, but relatively complicated relative to this class, What kind of class is only your own hobby. The following example shows a new and modified operation: New ------------------------------------------------------------------------------------------------------------------------------------------------ --- // 省 省 部分 部分 代 (上一面 上) ... cpbkcontactitem * contact = engine-> createemptyContactL (); // New Empty Communications Cleanupstack :: Pushl (Contact); _ lit (kfname, "king" ); _ LIT (KLName, "Chai"); _ LIT (KNumber, "13777777777"); // modified first nameTPbkContactItemField * field = contact-> FindField (EPbkFieldIdFirstName); field-> textStorage () -> SetTextL (KFName); / / modify last namefield = contact-> FindField (EPbkFieldIdLastName); field-> textStorage () -> SetTextL (KLName); // modify the phone number field = contact-> FindField (EPbkFieldIdPhoneNumberMobile); field-> textStorage () -> SetTextL (KNumber); ... // You can add other values // Modify the result to add to the database, and return the ID of this communication record, you can use TContactItemid ID = Engine-> AddNewContactL (* Contact);
Cleanupstack :: POPAndDestroy (Contact); -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - Implement modifications and new code similar, different, you need to find the field you want to modify, then modify, finally import database modification --------------------- -------------------- CPBKContactItem * Contact = Engine-> OpenContactLCX (ACONTACTID); Cleanupstack :: Pushl (Contact); // Find FieldtpBkcontactItemField * field = Contact-> Findfield (EPBKFIELDIDPHONENUMBERMOBILE); Cleanupstack :: Pushl (Field); _ Lit (Number, "135000000"); TBUF <11> Phonenumber (Number); // Set and confirm modify Field-> TextStorage () -> setTextl Phonenumber); Engine-> CommitContactL (* Contact);
Cleanupstack :: POPAndDestroy (2); ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -
The above content mainly introduces the various operations of Phonebook in the mobile phone. Because of the limited space, it can only list some commonly used operations, you can make a more in-depth understanding of the few classes mentioned above, and it will reach the expected results. I hope my summary is helpful to you! Finally, I wish you all a happy new year! - Feng Xiaoyun Next: "Symbian OS App Development - SMS Story" ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------- [C · K] Welcome you! Http://blog.9cbs.neet/welcome_ck new computer, new knowledge, new human being!