SMS Operation)

Source: Internet
Author: User
Tags sendmsg

Http://wiki.forum.nokia.com/index.php/%E7%9F%AD%E4%BF%A1%E6%93%8D%E4%BD%9C

This articleArticleDemonstrate the operations of text message processing.

Contents

[Hide]

    • 1 prerequisite
    • 2 send information
    • 3. Read the SMS folder
      • 3.1 inbox
      • 3.2 senders
      • 3.3 Draft
      • 3.4 sent information
    • 4. Read new text messages (online mode)
      • 4.1 obtain information
      • 4.2 get mobile phone number
    • 5. Delete the text message from the sent message (online mode)
    • 6. Delete the text message from the text message folder.
      • 6.1 inbox
      • 6.2 senders
      • 6.3 draft
      • 6.4 sent information
    • 7. Cancel "sending Status Report"
    • 8. send messages to multiple receivers
Prerequisites
    • Download as followsSmshandler.zip:
      • S60 Second Edition = smshander for s60 2nd. Zip
      • S60 Third Edition = smshander for s60 3rd. Zip
    • ExtractSmshandler.zipGetSmshandler. hAndSmshandler. cpp
    • Copy and pasteSmshandler. hGo to your project directory/INCDirectory.
    • Copy and pasteSmshandler. cppGo to your functional directory/SrcDirectory.
    • Edit your. MMPFile AdditionSmshandler. cppToSourceModule.
 
Source codeSmshandler. cpp
    • Edit your. MMPAdd necessary link libraries for Text Message Processing
 
// Libraries attached ded for SMS support-
Librarymsgs. Lib smcm. Lib gsmu. Lib mtur. Lib
    • Open yourCyrapplicationcontainer. hFile
    • SetSmshandler. hInclude
 
# Include "smshandler. H" // added for SMS handling
    • Define an smshandler Class Object
PRIVATE: // data
.......
.......
Csmshandler * ismshandler;
    • Open yourCyrapplicationcontainer. cppFile
    • Initialize the smshanlder object
 
Cyrapplicationcontainer: constructl ()......
{
.....
.....
Setrect (arect );
Activatel ();
 
Ismshandler = csmshandler: newl (); // smshandler
}
Send information
    • Define your own sendmsg () method:
 
Void cyrapplicationcontainer: sendmsg ()
{
Tbuf <128> smstext, phonenumber;
Smstext. Copy (_ L ("Test message "));
Phonenumber. Copy (_ L ("999999999"); // Replace number as per your needs
 
Ismshandler-> sendl (phonenumber, smstext );
}
Read the information sent by the inbox sender draft in the text message folder.
    • BelowCodeDemonstrate howInboxObtain information.Kmsvglobalinboxindexentryid.
    • SlaveSenderRead information, useKmsvglobaloutboxindexentryid
    • SlaveDraftRead information, useKmsvdraftentryid
    • SlaveSent informationRead information, useKmsvsententryid
Void csmshandler: readinbox ()
{
Hbufc * smscontent = hbufc: newlc (400 );
Hbufc8 * smscontent8 = hbufc8: newlc (400 );

Tmsvselectionordering sort;
Sort. setshowinvisibleentries (etrue); // we want to handle also the invisible entries

Cmsventry * inboxcontext = cmsventry: newl (* isession, kmsvglobalinboxindexentryid, sort); // reading messages from inbox folder
Cleanupstack: pushl (inboxcontext );

Cmsventryselection * entries = inboxcontext-> childrenl ();
Cleanupstack: pushl (entries );

Tint msgcount = entries-> count ();
For (tint I = 0; I <entries-> count (); I ++)
{

Tmsvid entryid = entries-> at (I );
Ismsmtm-> switchcurrententryl (entryid );

Cmsventry * entry = isession-> getentryl (* entries) [I]);
Cleanupstack: pushl (entry );

Cmsvstore * inboxstore = entry-> readstorel ();
Cleanupstack: pushl (inboxstore );
If (inboxstore-> hasbodytextl ())
{
Tmsventry entry1 = entry-> entry ();
Tbufc <50> atext (entry1.idetails); // gives you phone number
Tbuf16 <20> MSG;
MSG. Copy (atext );

Crichtext & richtext = ismsmtm-> body ();
Inboxstore-> restorebodytextl (richtext );
Const tint length = richtext. documentlength ();

Smscontent-> des (). Copy (richtext. Read (0, length); // gives you actual content (body) of SMS
Richtext. Reset ();

Smscontent8-> des (). Copy (smscontent-> des ());

Writetofile (smscontent8-> des (); // write sms body in the smsbody.txt File
}
Else
{
// No text in SMS
}
Cleanupstack: popanddestroy (2, entry );
}
Cleanupstack: popanddestroy (4, smscontent );
}
// Note that "smsbody.txt" used in the following code must be created beforehand as we are using open function from rfile API
Void csmshandler: writetofile (const tptrc8 & asmscontent8)
{
_ Partition (kfilespec, "\ smsbody.txt"); // file, in which SMS body will be stored
Tint Pos = 0;
Rfs fs;
FS. Connect ();
Rfile file;
Tint err = file. Open (FS, kfilespec, efilewrite );
If (ERR = kerrnone)
{
File. Seek (eseekend, POS );
File. Write (asmscontent8 );
File. Close ();
}
FS. Close ();
// File closed
}
Read new SMS (online mode) get information get mobile phone number
    • You canSmshandler. cppFileMessagereceivedl ()Method
    • Read the information and send it to your mobile phone according to the following code:
Void csmshandler: messagereceivedl (tmsvid aentryid)
{
Cmsventry * serverentry = isession-> getentryl (aentryid); // current entry
Cleanupstack: pushl (serverentry );
Tmsventry entry = serverentry-> entry (); // currently handled message entry

Entry. setnew (etrue );
Entry. setunread (etrue );
Entry. setvisible (etrue );

Serverentry-> changel (entry); // Commit Changes

// Added to retrieve Message Body
Const tdesc & descp = entry. ide.pdf; // idescription will have only first 32 characters from the message
Tbuf8 <40> messagearrived;
Messagearrived. Copy (descp );

// Added to retrieve phone number of the sender
Ismsmtm-> switchcurrententryl (aentryid );
Ismsmtm-> loadmessagel ();
Csmsheader & header = ismsmtm-> smsheader ();

Tptrc from = header. fromaddress ();
Const tdesc & phonenumber = from;

Cleanupstack: popanddestroy (serverentry );
}
Delete text messages from sent messages (online mode)
    • InSmshandler. cppOfHandlesessioneventl ()Add the following code
    • In this way, you can send information and delete it from the sent information folder.
Case emsventriesmoved:
{
// Entry ID is obtained from the session event arguments.
Tmsvid * entryid = static_cast (tmsvid *, 1_g2 );

// We are interested in messages that are moved to sent item folder
If (* entryid = kmsvsententryid)
{
Tmsvselectionordering sort;
Sort. setsorting (emsvsortbydatereverse );
Sort. setshowinvisibleentries (etrue); // we want to handle also the invisible entries

Cmsventry * parententry = cmsventry: newl (* isession, kmsvsententryid, sort );
Cleanupstack: pushl (parententry );

Cmsventryselection * entries = parententry-> childrenl ();
Cleanupstack: pushl (entries );

For (tint I = 0; I <entries-> count (); I ++)
{
If (parententry-> childdatal (entries-> at (I). imtmdata3! = Kuidmsgtypesms. iuid)
{
Parententry-> deletel (entries-> at (I ));
Break;
}
}
Cleanupstack: popanddestroy (entries );
Cleanupstack: popanddestroy (parententry );
}
Break;
}
}
Delete the information sent from the draft text message inbox sender from the text message folder.
    • the following code deletes the information in the inbox and uses kmsvglobalinboxindexentryid
    • the following code deletes the information in producer . The kmsvglobaloutboxindexentryid
    • the following code deletes the information in draft and uses kmsvdraftentryid
    • the following code deletes the information in sent message , kmsvsententryid
Void csmshandler: deletemessages ()
{
Tmsvselectionordering sort;
Sort. setshowinvisibleentries (etrue); // we want to handle also the invisible entries
 
Cmsventry * inboxcontext = cmsventry: newl (* isession, kmsvglobalinboxindexentryid, sort );
Cleanupstack: pushl (inboxcontext );
 
Cmsventryselection * entries = inboxcontext-> childrenl ();
Cleanupstack: pushl (entries );
 
Tint msgcount = entries-> count ();
Tint I;
For (I = 0; I <entries-> count (); I ++)
{
Tmsvid entryid = entries-> at (I );
Ismsmtm-> switchcurrententryl (entryid );
 
Cmsventry * entry = isession-> getentryl (* entries) [I]);
Cleanupstack: pushl (entry );
 
Entry-> deletel (entries-> at (I ));
Cleanupstack: popanddestroy (entry );
}
Cleanupstack: popanddestroy (entries );
Cleanupstack: popanddestroy (inboxcontext );
}
Cancel "sending Status Report"
    • OpenSmshandler. cppAddSetdeliverreport = efalseToCreatemsgl ()Function
 
Tbool csmshandler: createmsgl ()
{
.....
.....
Settings-> copyl (ismsmtm-> servicesettings (); // restore settings
Settings-> setdelivery (esmsdeliveryimmediately); // to be delivered immediately
Settings-> setdeliveryreport (efalse); // delivery report disabled here
Header. setsmssettingsl (* settings); // new settings
....
....
}

The following example shows how to obtain and delete a report: file: SMS deliveryreport deleting.zip

Send messages to multiple recipients
    • OpenSmshandler. cppInCreatemsgl ()OfAddaddresseel ()Add multiple numbers to the Method
 tbool csmshandler: createmsgl () 
{< br> ........
// recipient number is displayed also as the recipient alias.
entry. idetails. set (irecipientnumber);
// Add addressee.
tbuf <15> phonenumber2;
phonenumber2.copy (_ L ("9999999999 ")); // This is second number on which message will be sent
ismsmtm-> addaddresseel (irecipientnumber, entry. idetails);
ismsmtm-> addaddresseel (phonenumber2, entry. idetails);
......
.......
}

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.