×

Discussion Board

Results 1 to 4 of 4

Thread: Reading SMS

  1. #1
    Regular Contributor
    Join Date
    Oct 2008
    Posts
    91

    Reading SMS

    Hello All,
    I am trying to read an SMS and retrieve the content.
    I looked at the code available at Forum Nokia Wiki-SMS Operations.

    I have tried to use the following code:

    void CBackupContactsSmsHandler::ReadMessage()
    {
    HBufC* SMSContent = HBufC::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(entryID);
    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

    if(aText.Compare(_L("12345"))== 0)
    {
    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
    TBuf<400> aBuf;
    aBuf.Copy(SMSContent->Des());
    richText.Reset();
    CAknInformationNote* informationNote = new( ELeave ) CAknInformationNote;
    informationNote->ExecuteLD(aBuf); }
    }
    CleanupStack::PopAndDestroy(2);
    }
    CleanupStack::PopAndDestroy(3);
    }

    The code is working well. But it is not showing me the content of the first message that comes to the inbox incase the inbox is empty.
    I tried to debug. It stops at the line I have marked in RED. Can anyone please help me with this?

  2. #2
    Super Contributor
    Join Date
    Jan 2008
    Location
    Bangalore, India
    Posts
    777

    Re: Reading SMS

    If i am not wrong u want to get the body of newly arrived message.for this u can do like this.

    void CMessageHandler::HandleSessionEventL(TMsvSessionEvent aEvent, TAny *aArg1, TAny *aArg2, TAny *aArg3)
    {
    switch(aEvent)
    {
    case EMsvEntriesCreated:
    CMsvEntrySelection* entries = static_cast<CMsvEntrySelection*> (aArg1);
    iId = entries->At(0);

    break;

    case EMsvEntriesChanged:
    ReadMessage();
    break;

    default:
    break;
    }
    }

    and iId is a member variable of type "TMsvId" and use it in ur raed fun.
    Regards
    $-Nitesh-$

  3. #3
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,734

    Re: Reading SMS

    ReadStoreL may leave, that can be a reason. If debugging stops, you should read the last line in the output view, it is probably showing an error message, including the error code.
    Also note the existence of HasStoreL.

  4. #4
    Regular Contributor
    Join Date
    Oct 2008
    Posts
    91

    Re: Reading SMS

    Hello,
    The debugging does not stop at the mentioned line....it halts.
    The value of inboxStore is 'inboxStore = 0xcccccccc'
    There is no error message.

Similar Threads

  1. Reading SMS in Port 50000 Nokia 6275 CDMA
    By pmramprasath in forum Mobile Java General
    Replies: 14
    Last Post: 2009-01-07, 14:04
  2. Reading SMS in a specific Port (Running from background)
    By amishra in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2008-08-11, 22:07
  3. reading sms from the sms application
    By hatwarbabu in forum General Messaging
    Replies: 6
    Last Post: 2007-03-22, 19:40
  4. problem in reading sms index
    By hosam2010 in forum PC Suite API and PC Connectivity SDK
    Replies: 1
    Last Post: 2005-06-12, 17:39

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×