Symbian OS Application Development

Source: Internet
Author: User
Tags idate

Symbian OS application development-the story of SMS (1) favorites
Abstract: Short Message Service (SMS) is part of the GSM specification. Symbian OS SMS implements ETSI GSM 03.40 v7.4.0 technical based on SMS specifications. (This specification can be downloaded from the http://www.etsi.org) because our main task is to read, create, modify, delete and other operations, so the focus of this article on these operations, at the end of the article, we will also briefly talk about sending SMS messages.

First, as in previous articles, we will briefly introduce several important classes:
Cmsvsession
This class represents the communication channel between the client (client MTM, user interface MTM, or client message application) and the message server. Each client thread corresponds to an instance of this type. cmsvsession provides an effective way for the client to obtain messages from the message server in a timely manner. Before using any MTM or cmsventry object, a message client application must use opensyncl () or openasyncl () to create a session object.
Cclientmtmregistry
Registry has mastered all the MTM details available on the client. The message client can use this class to obtain de objects inherited from cbasemtm.
Cbasemtm
This class is mainly used to operate the content of SMS. For example, you can create and modify SMS. The usage method is described in the Code below. For more details, you can also view the help of the specific SDK.
Cmsventry
It is equivalent to an entry of a specific message server. The current entry is associated with its specific content. Cmsventry has two functions: one is to allow access to different types of data associated with this entry; the other is to run the sub-entry that accesses it. This class is only used on the client, and cmsvserverentry is used on the server.
Tmsventry
It is used to represent an entry of the message server and is mainly used to create SMS.

Let's take a look at some examples below: tmsvselectionordering sort;
Sort. setshowinvisibleentries (etrue); // sort all content, including hidden content
// Set the portal to outbox, that is, the mail box.
Cmsventry * entry = cmsventry: newl (* isession, kmsvglobaloutboxindexentryid, sort );
Cleanupstack: pushl (entry );
// Select all content
Cmsventryselection * entries = entry-> childrenl ();
Cleanupstack: pushl (entries );

TTime time;
// The time when the first information is obtained. At (0) indicates the first information. You can obtain the corresponding index from other information.
Time = entry-> childdatal (entries-> at (0). idate;
// The pop-up dialog box contains the number of the recipient of the first message.
Cakninformationnote * informationnote = new (eleave) cakninformationnote;
Informationnote-> executeld (Entry-> childdatal (entries-> at (0). idetails );

Cleanupstack: popanddestroy (2 );
 

------------------------------------------
Note: Some variables are not introduced, such as isession. This is because we have mentioned this in the previous article!
------------------------------------------
The above routine is used to show you how to obtain and operate SMS.
To put it simply, define the entry of a message server and associate it with Outbox. Then retrieve all the text message content in outbox and store it in the list pointed by the cmsventryselection pointer, you can operate the list to conveniently operate the SMS in outbox.
The following describes how to obtain the specific content of a single SMS, which are public variables. You can use them to obtain the details of SMS:
------------------------------------------
TTime idate (type and name)
Time (description) SMS time
--------------------------------------------------------------------------------
Tptrc ide.pdf
Description text message content
--------------------------------------------------------------------------------
Tptrc idetails
Details sender or receiver number
--------------------------------------------------------------------------------
Tint32 ierror
Error
--------------------------------------------------------------------------------
Tuid imtm
MTM
--------------------------------------------------------------------------------
Tint32 imtmdata1
MTM data 1: this can be used for any purpose by an MTM.
--------------------------------------------------------------------------------
Tint32 imtmdata2
MTM data 2: this can be used for any purpose by an MTM.
--------------------------------------------------------------------------------
Tint32 imtmdata3
MTM data 3: this can be used for any purpose by an MTM.
--------------------------------------------------------------------------------
Tmsvid irelatedid
Related Folder Id.
--------------------------------------------------------------------------------
Tmsvid iserviceid
Service ID.
--------------------------------------------------------------------------------
Tint32 isize
Size SMS size
--------------------------------------------------------------------------------
Tuid itype
Entry type
--------------------------------------------------------------------------------
Tint32 iwdpportnumber
Port Number
--------------------------------------------------------------------------------
Tint32 ibiotype
Bio Message Type
------------------------------------------
By using the above variables, We can get all the information in SMS. I will only introduce the several frequently used variables. The rest can be studied in detail when you use them. The above routine is very simple and clear, and it will be easier to use. Next we can use the above method to implement the delete operation as well:

Tmsvselectionordering sort;
Sort. setshowinvisibleentries (etrue );
Cmsventry * entry = cmsventry: newl (* isession, kmsvdraftentryid, sort );
Cleanupstack: pushl (entry );

Cmsventryselection * entries = entry-> childrenl ();
Cleanupstack: pushl (entries );
Tint I = entries-> count ();
For (tint ncount = 0; ncount <I; ncount ++)
Entry-> deletel (entries-> at (ncount ));
// Information to the user
Ieikonenv-> infomsg (_ L ("deleteall done! "));
Cleanupstack: popanddestroy (2 );

If you have understood the above operation to read SMS information, it is not hard to understand this operation. The difference is that a deletel () function is called, which is defined in the class cmsventry. It can delete the SMS at the fixed index position. For more information, see the related SDK help

With the above understanding, it is not difficult to see that the operation of SMS is actually similar to the vCard we mentioned above. Let's take a look at how to export the content of SMS to a file.
The class cbasemtm is used here. Let's look at the following routine:

Ismsmtm-> switchcurrententryl (aentryid );
Ismsmtm-> loadmessagel (); // load the message

Crichtext & Body = ismsmtm-> body (); // the content of the SMS is stored in the crichtext control object.
Tptrc MSG (body. Read (0 ));
Writetofilel (MSG );

Ismsmtm is a pointer variable of the cbasemtm type. It must be initialized, as follows:
1. isession = cmsvsession: openasyncl (* This );
// The parameter of this function should be any class inherited from mmsvsessionobserver... it will establish an asynchronous connection with the session library...
// Then you can receive the event emsvserverready in the handlesessioneventl function...
// When the event arrives, it indicates that the call between the server has been established... then get the MTM registry and return the sms mtm...
2. imtmreg = cclientmtmregistry: newl (* isession );
3. imtmsms = static_cast <csmsclientmtm *> (imtmreg-> newmtml (kuidmsgtypesms ));

The specific implementation of the writetofilel () function is as follows:

Void writetofilel (const tptrc & amsg)
{// Set the storage path and file
_ Partition (kdirname, "// system // apps // MyApp/Data ");
_ Partition (kfilename, "// system // apps // MyApp // data // msgbody.txt ");
// Connect to the file server and generate the corresponding folder
RFS filesession;
Filesession. Connect ();
Filesession. mkdirall (kdirname );

Rfilewritestream writer;
Writer. pushl ();
User: leaveiferror (writer. Replace (filesession,
Kfilename, efilewrite ));
// Write and confirm the file
Writer <amsg;
Writer. commitl ();

Cleanupstack: popanddestroy ();
Filesession. Close ();
}
// The following header file will be used
# Include <smsclnt. h>
# Include <smut. h>

The above steps are clear and clear. You should pay attention to the usage of the cbasemtm class, because the new SMS will also focus on this class, in addition, more times are used.

The process for creating an SMS is complex. Here are some main steps:

Tmsventry newentry;
Newentry. imtm
Newentry. itype
Newentry. iserviceid
Newentry. idate. hometime (); // It is generally set to the current time.
Newentry. setinpreparation (etrue); // set it to true.

After setting the above parameters, you can use the cbasemtm class to complete the new operation.

Cbasemtm * imtmsms;
...
Imtmsms-> switchcurrententryl (kmsvglobalinboxindexentryid); // set it to the inbox
Imtmsms-> entry (). createl (newentry );

Long smsid = newentry. ID (); // get the ID of the new SMS
Imtmsms-> switchcurrententryl (smsid );
// Set SMS details
_ Empty (ksmsbody, "Hello world! ");
Crichtext & Body = imtmsms-> body ();
Body. Reset ();
Body. insertl (0, ksmsbody );
Newentry. ide.pdf. Set (ksmsbody );
// Set the mobile phone number of the recipient or sender of the SMS
Imtmsms-> addaddresseel (_ L ("13500000000 "));
Newentry. idetails. Set (_ L ("13500000000 "));
Imtmsms-> entry (). changel (newentry );
// Do not forget to save
Imtmsms-> savemessagel ();

In this way, you can create an SMS. Of course, with the experience of creating an SMS, it is not difficult to modify the SMS information. The main steps can be divided into three steps:
1. give some information about the SMS to be modified, such as ID, index, location, or other
2. Search for the qualified SMS and save these results
3. Use the search results to modify the SMS information and confirm the changes.
Here, we will not make a detailed analysis on the changes to SMS. You can try it yourself!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.