×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    7

    Problem of setting body text for MMS

    Hi,

    I set all information for MMS, including subject, phone #, body text, and attached image file. After I sent it out, in the outbox, I can't see body text, but other fields are fine. (I use emulator for test, due to capability, I not yet try it on the phone)

    void CMessageSend_S60::CreateMMSL
    (
    TDesC16& aBodyText,
    TDesC16& aSubject,
    TDesC16& aAttachedFilename,
    TDesC16& aPhonenum
    )
    {

    // - CMsvEntry accesses and acts upon a particular Message Server entry.
    // - NewL() does not create a new entry, but simply a new object to access an existing entry.
    // - It takes in as parameters the client's message server session,
    // ID of the entry to access and initial sorting order of the children of the entry.
    CMsvEntry* theEntry = CMsvEntry::NewL
    (
    *iSession,
    KMsvGlobalOutBoxIndexEntryId,
    TMsvSelectionOrdering()
    );
    CleanupStack::PushL( theEntry );

    // Set context to the parent folder (Outbox)
    iMmsMtm->SwitchCurrentEntryL( theEntry->EntryId() );

    // Create new message in the parent folder (Outbox) and set it as the current context.
    iMmsMtm->CreateMessageL( iMmsMtm->DefaultServiceL() );

    CleanupStack::PopAndDestroy(); // entry

    // Set recipients
    // use this to add the "To" recipients.
    iMmsMtm->AddAddresseeL( aPhonenum );

    // Set message subject
    //iMmsMtm->SetSubjectL( aSubject );
    iMmsMtm->SetSubjectL( aBodyText );


    // Doesn't work, don't know why, so insert bodytext as attachment file
    // Set body text
    CRichText& richBodyText = iMmsMtm->Body();
    richBodyText.Reset();
    richBodyText.InsertL( KBodyTextStartPosition, aBodyText );




    // Set attchment file, including image file
    TRAP( err, SetAttachmentToMsgL( aAttachedFilename ) );

    if( err != KErrNone )
    {
    User::Leave( err );
    }

    TMsvEntry theTMsvEntry = iMmsMtm->Entry().Entry();

    // Set InPreparation to false
    theTMsvEntry.SetInPreparation(EFalse);
    // Mark as visible, after this the message can be seen in Outbox and,
    // after sending, in Sent folder.
    theTMsvEntry.SetVisible(ETrue);

    // Commit changes
    iMmsMtm->Entry().ChangeL(theTMsvEntry);
    //Save the changes
    iMmsMtm->SaveMessageL();


    // Send Message
    SendMessageL();
    }
    Does anyone know what the problem is?
    Thanks in advance!

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,671

    Re: Problem of setting body text for MMS

    The MMS MTM does not make use of the default 'Body' member. Check 'mmssend' example of S60 2nd edition SDKs or the MtmsExample of the EMCC-book (download the samples from http://www.forum.nokia.com/main/plat...s60/books.html) for details.

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    10

    Re: Problem of setting body text for MMS

    You can achieve the same purpose by adding a text attachment.

  4. #4
    Registered User
    Join Date
    Jul 2006
    Posts
    7

    Re: Problem of setting body text for MMS

    Hi wizard_hu,

    Got it! Thanks a lot!

    I use CMmsClientMtm::CreateTextAttachmentL() to insert MMS body text instead of CMmsClientMtm::Body(), and it works fine.

    After sending MMS out, I am watching the incoming MMS, and want to get the MMS body text. I use CMsvStore::HasBodyTextL() to check if the store has a body text, but it always return false. So, I can't get MMS bodytext.


    By the way, I am using S60 3rd SDK.


    void CMessageSend_S60::SetAttachmentToMsgL( TDesC& aBodyText, TDesC& aAttachedFileName )
    {
    //Opening store
    CMsvStore* theStore = iMmsMtm->Entry().EditStoreL();
    CleanupStack::PushL( theStore );

    RFile theAttachment;
    //open theAttachment file
    TInt err = theAttachment.Open
    (
    CCoeEnv::Static()->FsSession(),
    aAttachedFileName,
    EFileShareReadersOnly | EFileRead
    );

    CleanupClosePushL( theAttachment );

    //Check that the theAttachment file exist.
    if( err != KErrNone )
    {
    theAttachment.Close();
    CleanupStack::PopAndDestroy(2); // theAttachment, theStore

    User::Leave( err );
    }
    else
    {
    //mime header
    CMsvMimeHeaders* theMimeHeaders = CMsvMimeHeaders::NewL();
    CleanupStack::PushL( theMimeHeaders );
    theMimeHeaders->SetSuggestedFilenameL( KFileName );

    // Represents a single attachment and information about the attachment
    CMsvAttachment* theAttaInfo =
    CMsvAttachment::NewL( CMsvAttachment::EMsvFile );
    CleanupStack::PushL( theAttaInfo );

    //Mime Type
    TBufC8<10> theMimeType(KMimeType);

    TMsvAttachmentId theAttachId = KMsvNullIndexEntryId;

    // Attach body text to attachment
    iMmsMtm->CreateTextAttachmentL
    (
    *theStore,
    theAttachId,
    aBodyText,
    KBodyTextFileName
    );


    //Attachment file must be an public folder
    iMmsMtm->CreateAttachment2L
    (
    *theStore,
    theAttachment,
    theMimeType,
    *theMimeHeaders,
    theAttaInfo,
    theAttachId
    );

    // Ownership of attachmentinfo is transferred to attachment manager
    // It must not be deleted by caller.
    CleanupStack::Pop( theAttaInfo );
    CleanupStack::PopAndDestroy( theMimeHeaders ); // theMimeHeaders

    theStore->CommitL();
    theAttachment.Close();

    CleanupStack::PopAndDestroy(); // theAttachment
    CleanupStack::PopAndDestroy(); // store
    }
    }

    void CMessageSend_S60::HandleSessionEventL
    (
    TMsvSessionEvent aEvent,
    TAny* aArg1,
    TAny* aArg2,
    TAny* aArg3
    )
    {
    switch (aEvent)
    {
    // This event tells us that the session has been opened
    case EMsvServerReady:
    CompleteConstructL(); // Construct the mtm registry & MMS mtm
    break;

    case EMsvEntriesCreated:
    {
    ProcessNewMsg( aArg1, aArg2 );
    }
    break;

    default:
    break;
    }
    }


    void CMessageSend_S60::ProcessNewMsg
    (
    TAny* aArg1,
    TAny* aArg2
    )
    {
    // entry id from the session event
    TMsvId *parent = static_cast<TMsvId*>( aArg2 );
    if ( KMsvGlobalInBoxIndexEntryId == *parent )
    {
    // Go through new messages..
    // We take the created entries into a selection
    CMsvEntrySelection* entries =
    static_cast<CMsvEntrySelection*>(aArg1);

    // entry pointer for making changes in the actual message contexts
    CMsvEntry* entry = NULL;
    TMsvId theNewMsgId;

    //Process each created entry, one at a time.
    for (TInt i = 0; i < entries->Count(); i++)
    {


    // Setting all messages in the selection as invisible
    // this reserves memory for a new CMsvEntry
    theNewMsgId = entries->At(i);

    entry = iSession->GetEntryL( theNewMsgId );
    entry->SetEntryL(theNewMsgId);

    // Open the store
    CMsvStore* theStore = entry->ReadStoreL();
    CleanupStack::PushL( theStore );

    // Get body text
    if( theStore->HasBodyTextL() )
    {
    CRichText* theRichText = CRichText::NewL
    (
    CEikonEnv::Static()->SystemParaFormatLayerL(),
    CEikonEnv::Static()->SystemCharFormatLayerL()
    );

    CleanupStack::PushL( theRichText );
    theStore->RestoreBodyTextL( *theRichText );


    CAknInformationNote* informationNote = new ( ELeave ) CAknInformationNote;
    informationNote->ExecuteLD( theRichText->Read(0) );

    CleanupStack::PopAndDestroy( theRichText);
    }

    CleanupStack::PopAndDestroy( theStore );

    delete entry;
    }
    }
    }

  5. #5
    Registered User
    Join Date
    Jul 2006
    Posts
    7

    Angry Re: Problem of setting body text for MMS

    After study, I found I have to watch for EMsvEntriesCreated and EMsvEntriesChanged events in the inbox. When EMsvEntriesCreated event aarives, it has not been stored yet, so I can't read data from the entry; when EMsvEntriesChanged arrived, I have to tell it's a new message or change to an existing message.

    So, I did some modification. But I still got false value for CMsvStore::HasBodyTextL(). I really don't know why I can't read MMS body text.


    void CMessageSend_S60::HandleSessionEventL
    (
    TMsvSessionEvent aEvent,
    TAny* aArg1,
    TAny* aArg2,
    TAny* aArg3
    )
    {
    switch (aEvent)
    {
    // This event tells us that the session has been opened
    case EMsvServerReady:
    CompleteConstructL(); // Construct the mtm registry & MMS mtm
    break;

    case EMsvEntriesCreated: // Message created
    {
    if ( KMsvGlobalInBoxIndexEntryId == *(static_cast<TMsvId*>( aArg2 )) )
    {
    CMsvEntrySelection* entries = static_cast<CMsvEntrySelection*>(aArg1);
    iNewMsgId = entries->At(0);
    }
    }
    break;

    case EMsvEntriesChanged:
    {
    if ( KMsvGlobalInBoxIndexEntryId == *(static_cast<TMsvId*>( aArg2 )) )
    {
    CMsvEntrySelection* entries = static_cast<CMsvEntrySelection*>(aArg1);
    if( iNewMsgId == entries->At(0) )
    {
    // It's the same message we received the EMsvEntriesCreated event for
    ProcessNewMsg();
    }
    }
    }
    break;

    default:
    break;
    }
    }

    void CMessageSend_S60::ProcessNewMsg()
    {
    // entry pointer for making changes in the actual message contexts
    CMsvEntry* entry = iSession->GetEntryL( iNewMsgId );
    entry->SetEntryL(iNewMsgId);

    // Open the store
    CMsvStore* theStore = entry->ReadStoreL();
    CleanupStack::PushL( theStore );

    // Get body text
    if( theStore->HasBodyTextL() )
    {
    CRichText* theRichText = CRichText::NewL
    (
    CEikonEnv::Static()->SystemParaFormatLayerL(),
    CEikonEnv::Static()->SystemCharFormatLayerL()
    );

    CleanupStack::PushL( theRichText );
    theStore->RestoreBodyTextL( *theRichText );


    CAknInformationNote* informationNote = new ( ELeave ) CAknInformationNote;
    informationNote->ExecuteLD( theRichText->Read(0) );

    CleanupStack::PopAndDestroy( theRichText);
    }

    CleanupStack::PopAndDestroy( theStore );

    delete entry;
    }

  6. #6
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,671

    Re: Problem of setting body text for MMS

    Well the 'MMS MTM does not use its Body() member' also applies for incoming MMSs. Unfortunately I do not know what you should exactly do, but I would start with CMmsClientMtm::GetAttachmentsL.

  7. #7
    Registered User
    Join Date
    Jul 2006
    Posts
    7

    Re: Problem of setting body text for MMS

    Well I want to read the text file of incoming MMS and there is no CMmsClientMtm::GetAttachmentsL(I am using S60 3rd Edition SDK). Maybe I should start with CMsvStore::AttachmentManagerL() to get MMsvAttachmentManager::GetAttachmentFileL(). Thansk !

  8. #8
    Registered User
    Join Date
    Feb 2007
    Posts
    4

    Re: Problem of setting body text for MMS

    Hi,

    Can somebody quickly share some smaple code to read MMS messages from Inbox. Thanks in advance!

    Rush!
    CRB

  9. #9
    Regular Contributor
    Join Date
    Aug 2003
    Posts
    128

    Re: Problem of setting body text for MMS

    // Get message body from entry storage (CMsvStore). CMsvStore stores whole
    // message, not summary information ( see GetMessageIndexBodyTextL() ).
    TBool CMMSMtmsEngine::GetMessageL( TMsvId aMessageId, TDes& aMessage)
    {
    iMmsMtm->SwitchCurrentEntryL( aMessageId );

    if ( iMmsMtm->Entry().HasStoreL() )
    {
    // SMS message is stored inside Messaging store.
    CMsvStore* store = iMmsMtm->Entry().ReadStoreL();
    CleanupStack::PushL(store);

    MMsvAttachmentManager& attachManager = store->AttachmentManagerL();

    RFile file= attachManager.GetAttachmentFileL(0);

    HBufC8* buf = HBufC8::NewL(100) ;
    TPtr8 pBuf = buf->Des() ;
    file.Read(pBuf); //pBuf now contains the text
    file.Close();

    CleanupStack::PopAndDestroy(store);
    }
    else
    {
    return EFalse;
    }

    return ETrue;
    }

  10. #10
    Registered User
    Join Date
    Nov 2009
    Posts
    19

    Re: Problem of setting body text for MMS

    Quote Originally Posted by zhenLeow View Post
    // Get message body from entry storage (CMsvStore). CMsvStore stores whole
    // message, not summary information ( see GetMessageIndexBodyTextL() ).
    TBool CMMSMtmsEngine::GetMessageL( TMsvId aMessageId, TDes& aMessage)
    {
    iMmsMtm->SwitchCurrentEntryL( aMessageId );

    if ( iMmsMtm->Entry().HasStoreL() )
    {
    // SMS message is stored inside Messaging store.
    CMsvStore* store = iMmsMtm->Entry().ReadStoreL();
    CleanupStack::PushL(store);

    MMsvAttachmentManager& attachManager = store->AttachmentManagerL();

    RFile file= attachManager.GetAttachmentFileL(0);

    HBufC8* buf = HBufC8::NewL(100) ;
    TPtr8 pBuf = buf->Des() ;
    file.Read(pBuf); //pBuf now contains the text
    file.Close();

    CleanupStack::PopAndDestroy(store);
    }
    else
    {
    return EFalse;
    }

    return ETrue;
    }
    this method is working for english body, but if the body is chinese words, there will be a problem. does anybody have a good idea to handle the chinese words MMS body?

    Thanks.
    John

Similar Threads

  1. read string from text file problem
    By sim.sim in forum Symbian
    Replies: 9
    Last Post: 2006-05-24, 07:41
  2. N90 Video editing - problem add Text to video
    By thongtom in forum General Development Questions
    Replies: 0
    Last Post: 2005-10-27, 09:47
  3. Nokia 60 emulator setting problem
    By ravi_qbit in forum Mobile Java General
    Replies: 0
    Last Post: 2005-10-21, 07:23

Posting Permissions

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