×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    49

    Thumbs up SMS Handler not working when the application is running in the foreground

    Hello all..
    Iam trying to read the incoming message when it arrives...for that iam using the SMSHandler class which I found in wiki...
    But this class is behaving differently..
    When Iam running it in background,It is working fine..but when I run it in foreground,
    Some times it is reading the message and some times it is not....
    here is my code..

    void CSmsHandler::HandleSessionEventL( TMsvSessionEvent aEvent,
    TAny* aArg1, TAny* aArg2, TAny* /*aArg3*/)
    {
    switch ( aEvent )
    {
    // A new entry has been created on the message server.

    case EMsvEntriesCreated:

    {
    TMsvId* entryId = STATIC_CAST( TMsvId*, aArg2 );
    if ( *entryId == KMsvGlobalInBoxIndexEntryId )
    {
    CMsvEntrySelection* entries = static_cast<CMsvEntrySelection*>(aArg1);
    if(entries)
    {
    CMsvEntry* entry = 0;
    for(TInt i = 0; i < entries->Count(); i++)
    {
    entry = iSession->GetEntryL(entries->At(i));
    if(entry->Entry().iMtm == KUidMsgTypeSMS)
    {
    TMsvId id = entry->EntryId();
    ReadInbox(id);
    }
    }
    }
    }
    }
    }


    void CSmsHandler::ReadInbox(TMsvId entryID)
    {

    TMsvSelectionOrdering sort;
    sort.SetShowInvisibleEntries(ETrue);

    CMsvEntry* inboxContext=CMsvEntry::NewL(*iSession,KMsvGlobalInBoxIndexEntryId ,sort); // Reading Messages from Inbox Folder
    CleanupStack::PushL(inboxContext);

    CMsvEntrySelection* entries = inboxContext->ChildrenL();
    CleanupStack::PushL( entries );

    TInt i = entries->Count();
    //TMsvId entryID = entries->At(i-1);
    iSmsMtm->SwitchCurrentEntryL(entryID);

    CMsvEntry* entry= iSession->GetEntryL((*entries)[i-1]);
    CleanupStack::PushL(entry);

    CMsvStore* inboxStore= entry->ReadStoreL();
    CleanupStack::PushL(inboxStore);

    if (inboxStore->HasBodyTextL())
    {
    TMsvEntry entry1 = entry->Entry();
    iSmsMtm->SwitchCurrentEntryL(entryID);
    iSmsMtm->LoadMessageL();
    CSmsHeader& header = iSmsMtm->SmsHeader();

    TPtrC from = header.FromAddress();
    const TDesC& phoneNumber = from;

    CRichText& richText= iSmsMtm->Body();
    inboxStore->RestoreBodyTextL(richText);
    const TInt length = richText.DocumentLength();
    TBuf8<160> aSMSmsg;
    aSMSmsg.Copy(richText.Read(0,length)); // Gives actual content(Body) of SMS
    richText.Reset();

    }
    }

    will it behave differently when it is running in foreground and background???

    Can anybody help me out to solve this problem....its very very urgent....

    Thanks in advance...

    Chandu

  2. #2
    Nokia Developer Expert
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,142

    Re: SMS Handler not working when the application is running in the foreground

    you should mpropably debug and see what is actually happening with your code..

  3. #3
    Registered User
    Join Date
    Oct 2008
    Location
    India
    Posts
    184

    Re: SMS Handler not working when the application is running in the foreground

    Hi.. chandrashekar..

    follow the following code samaple.... which works fine...
    http://www.forum.nokia.com/info/sw.n..._1_en.zip.html

    I was also face the problem with SMSHandler code snippet which I found in wiki....
    Thanks & Regards,
    --PRANAY--

  4. #4
    Registered User
    Join Date
    Jan 2008
    Posts
    49

    Re: SMS Handler not working when the application is running in the foreground

    Hi symbianyucca...
    Thanks for ur quick reply...
    I have debugged it..
    All the times it is coming to the ReadInBox(),but I have a problem is in the code here ...

    void CSmsHandler::ReadInbox(TMsvId entryID)
    {
    ////upto this point,the fun is executing...

    TMsvSelectionOrdering sort;
    sort.SetShowInvisibleEntries(ETrue);

    CMsvEntry* inboxContext=CMsvEntry::NewL(*iSession,KMsvGlobalInBoxIndexEntryId ,sort); // Reading Messages from Inbox Folder
    CleanupStack::PushL(inboxContext);

    CMsvEntrySelection* entries = inboxContext->ChildrenL();
    CleanupStack::PushL( entries );

    TInt i = entries->Count();
    //TMsvId entryID = entries->At(i-1);
    iSmsMtm->SwitchCurrentEntryL(entryID);

    CMsvEntry* entry= iSession->GetEntryL((*entries)[i-1]);
    CleanupStack::PushL(entry);

    CMsvStore* inboxStore= entry->ReadStoreL();
    CleanupStack::PushL(inboxStore);

    ///here it is not coming...
    }


    can u help me out pls.....
    I will be very thankfull to u....

  5. #5
    Nokia Developer Expert
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,142

    Re: SMS Handler not working when the application is running in the foreground

    So which line is leaving in there ?, you could also try using TRAP to catch the actual error.

  6. #6
    Registered User
    Join Date
    Jan 2008
    Posts
    49

    Re: SMS Handler not working when the application is running in the foreground

    Hi symbianyucca and pranay_preet....
    Sorry for the late reply....

    I have solved my problem...
    The actual problem was, when the process is in foreground,It was taking some extra time to read the entire message...So the condition failed in the statment

    if (inboxStore->HasBodyTextL())

    For that I have done something like this..
    I have given some delay(10 Sec) before calling ReadInbox() by placing a User::After(10000000).

    Now it is working fine...

    Let me know if I am wrong anywhere...


    Thankyou so much for ur support....

    Regards
    Chandu

Similar Threads

  1. How do I keep Console application running?
    By MehulPatel in forum General Messaging
    Replies: 2
    Last Post: 2008-07-25, 06:25
  2. SMS remains in Outbox in "Waiting" state.
    By MehulPatel in forum General Messaging
    Replies: 10
    Last Post: 2008-07-16, 08:23
  3. Replies: 1
    Last Post: 2008-05-08, 12:32
  4. Sending SMS to Emulator through desktop application
    By iqbalaminkhan in forum Mobile Web Site Development
    Replies: 0
    Last Post: 2006-12-22, 05:01
  5. Developing SMS application
    By vishwakanand in forum PC Suite API and PC Connectivity SDK
    Replies: 2
    Last Post: 2003-08-12, 13:44

Posting Permissions

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