×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Regular Contributor
    Join Date
    Oct 2008
    Location
    Bangalore,India
    Posts
    129

    Incoming SMS notification

    Hi ,

    I am trying to send sms to inbox on emulator.
    sending works perfectly, but im unable to get any event notification .

    here is my code

    [CODE
    // INCLUDE FILES

    #ifdef __WINS__
    const TMsvId KObservedFolderId = KMsvDraftEntryId;
    #else
    const TMsvId KObservedFolderId = KMsvGlobalInBoxIndexEntryId;
    #endif
    const TMsvId KInbox = KMsvGlobalInBoxIndexEntryId;


    CSmsHandler::CSmsHandler(MSMSRecCallBack& aObserver) :
    CActive(CActive::EPriorityStandard), iObserver(aObserver)
    {
    CActiveScheduler::Add(this);
    iNextUnread = 0; // index of next unread message in iSelection
    }
    void CSmsHandler::ConstructL()
    {
    // Session to message server is opened asynchronously.
    iSession = CMsvSession::OpenAsyncL(*this);

    // Entry selection for all received messages.
    iSelection = new (ELeave) CMsvEntrySelection();
    }
    CSmsHandler* CSmsHandler::NewL(MSMSRecCallBack& aObserver)
    {
    CSmsHandler* self = NewLC(aObserver);
    CleanupStack::Pop(self);
    return self;
    }
    CSmsHandler* CSmsHandler::NewLC(MSMSRecCallBack& aObserver)
    {
    CSmsHandler* self = new (ELeave) CSmsHandler(aObserver);
    CleanupStack::PushL(self);
    self->ConstructL();
    return self;
    }
    CSmsHandler::~CSmsHandler()
    {
    Cancel(); // cancel any outstanding request

    delete iOperation;
    delete iMtmUiRegistry;
    delete iSelection;
    delete iSmsMtm;
    delete iMtmRegistry;
    delete iSession; // session must be deleted last
    }
    void CSmsHandler:oCancel()
    {
    if (iOperation)
    {
    iOperation->Cancel();
    }
    }
    void CSmsHandler::RunL()
    {
    User::LeaveIfError(iStatus != KErrNone);

    // Determine the current operations progress.
    // ProgressL returns an 8 bit descriptor.
    TBufC8<KMsvProgressBufferLength> progress(iOperation->ProgressL());
    _LIT8( KCompare, "KErrNone" );
    User::LeaveIfError(!progress.Compare(KCompare));

    // The pointer to the current CMsvOperation object is no longer needed.
    delete iOperation;
    iOperation = NULL;

    // Determine which request has finished.
    switch (iState)
    {
    case EWaitingForMoving:
    // Once a message is moved to Outbox it is scheduled for sending.
    ScheduleL();
    break;

    case EWaitingForScheduling:
    {
    TMsvEntry entry(iSmsMtm->Entry().Entry());
    TInt state(entry.SendingState());

    if (state == KMsvSendStateWaiting || state
    == KMsvSendStateScheduled)
    {
    }

    break;
    }

    default:
    break;
    }
    }
    void CSmsHandler::HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1,
    TAny* aArg2, TAny* /*aArg3*/)
    {
    switch (aEvent)
    {
    // Session to server established
    case EMsvServerReady:
    {
    TMsvId serviceId(KUidMsgTypeSMS.iUid); // SMS service id

    // Determine if the event was succesful.
    // ServiceProgress inserts TBuf8 value in progress.
    TBuf8<KBfrLength> progress;
    iSession->ServiceProgress(serviceId, progress);
    _LIT8( KCompare, "KErrNone" );

    if (progress.Compare(KCompare))
    {
    // Check that MtmRegistry has not already been accessed.
    if (!iMtmRegistry)
    {
    AccessMtmL();
    }
    }
    break;
    }

    // A new entry has been created on the message server.
    case EMsvEntriesCreated:
    {
    // Entry id is obtained from the session event arguments.
    TMsvId* entryId = STATIC_CAST( TMsvId*, aArg2 );

    // We are interested in messages that are created in Inbox.
    if (*entryId != KMsvGlobalInBoxIndexEntryId)
    {
    break;
    }

    // We take the created entries into a selection
    CMsvEntrySelection* newEntries = STATIC_CAST( CMsvEntrySelection*, aArg1 );

    // Process each created entry.
    for (TInt i(0); i < newEntries->Count(); i++)
    {
    // We are interested in SMS messages.
    if ((iSession->GetEntryL(newEntries->At(i))) ->Entry().iMtm
    == KUidMsgTypeSMS)
    {
    // Add the entry to the selection of all received messages.
    iSelection->AppendL(newEntries->At(i), 1);

    // Set received messages visible.
    MessageReceivedL(newEntries->At(i));
    }
    }

    break;
    }
    case EMsvEntriesChanged:
    {
    // Look for changes. When using the emulator
    // observed folder is drafts, otherwise inbox
    if (aArg2 && *(static_cast<TMsvId*> (aArg2)) == KObservedFolderId)
    {
    CMsvEntrySelection* entries =
    static_cast<CMsvEntrySelection*> (aArg1);
    if (!entries && entries->Count() < 1)
    {
    return;
    }
    else if (iNewMessageId == entries->At(0))
    {
    if (!iMsvEntry)
    {
    return;
    }
    // Set entry context to the new message
    iMsvEntry->SetEntryL(iNewMessageId);
    // Check the type of the arrived message and
    // that the message is complete
    // Only SMS's are our consern
    if (iMsvEntry->Entry().iMtm != KUidMsgTypeSMS
    || !iMsvEntry->Entry().Complete())
    {
    return;
    }
    // Read-only store
    CMsvStore* store = iMsvEntry->ReadStoreL();
    CleanupStack::PushL(store);
    // Get address of received message.
    iAddress.Copy(iMsvEntry->Entry().iDetails);
    // Body text
    if (store->HasBodyTextL())
    {
    CRichText* richText = CRichText::NewL(
    CEikonEnv::Static()->SystemParaFormatLayerL(),
    CEikonEnv::Static()->SystemCharFormatLayerL());
    CleanupStack::PushL(richText);
    store->RestoreBodyTextL(*richText);
    TPtrC ptr = richText->Read(0,
    richText->DocumentLength());
    iMessage.Copy(ptr);
    CleanupStack::PopAndDestroy(richText);
    CleanupStack::PopAndDestroy(store);
    // Send message and phone number to caller
    iObserver.GotSMSMessageL(iMessage);


    }
    else
    {
    CleanupStack::PopAndDestroy(store);
    }
    }
    }
    break;
    }
    case EMsvCloseSession:
    case EMsvServerTerminated:
    case EMsvGeneralError:
    case EMsvServerFailedToStart:
    {
    // iSmsAppUi->ServerDown( aEvent ); // close application
    break;
    }

    // All other events are ignored.
    default:
    break;
    }
    }
    void CSmsHandler::AccessMtmL()
    {
    // Create an MTM Registry object.
    iMtmRegistry = CClientMtmRegistry::NewL(*iSession);

    // Create an SMS Client MTM object.
    iSmsMtm = STATIC_CAST( CSmsClientMtm*, iMtmRegistry->NewMtmL( KUidMsgTypeSMS ) );
    }
    void CSmsHandler::SendL(const TDesC& aRecipientNumber,
    const TDesC& aMessageText)
    {
    iRecipientNumber = aRecipientNumber;
    iMessageText = aMessageText;
    SMS2Inbox();
    }
    void CSmsHandler::SMS2Inbox()
    {
    //TBool iSendingSms = ETrue;
    TBuf<10> aAddress(_L("Nokia"));
    TBuf<20> aDescription(_L("Important Message"));
    _LIT(KTxt1,"Hi phone owner, how r u?");
    TBuf<150> iMessage;
    iMessage.Copy(KTxt1);
    iMtmRegistry = CClientMtmRegistry::NewL(*iSession);
    iSmsMtm = STATIC_CAST( CSmsClientMtm*, iMtmRegistry->NewMtmL(KUidMsgTypeSMS));
    iSmsMtm->SwitchCurrentEntryL(KMsvGlobalInBoxIndexEntryId);
    //inbox
    iSmsMtm->CreateMessageL(KUidMsgTypeSMS.iUid);
    CSmsHeader& iHeader = iSmsMtm->SmsHeader();
    iHeader.SetFromAddressL(aAddress);
    CRichText& body = iSmsMtm->Body();
    body.Reset();
    body.InsertL(0, iMessage);
    TMsvEntry entry = iSmsMtm->Entry().Entry();
    entry.SetInPreparation(EFalse);
    entry.SetVisible(ETrue);
    entry.iDate.HomeTime();
    entry.iDescription.Set(aDescription);
    entry.iDetails.Set(aAddress);
    entry.SetUnread(ETrue);
    iSmsMtm->Entry().ChangeL(entry);
    iSmsMtm->SaveMessageL();
    }
    TBool CSmsHandler::ValidateL()
    {
    // Empty part list to hold the result.
    TMsvPartList result(KMsvMessagePartNone);

    // Validate message body.
    result = iSmsMtm->ValidateMessage(KMsvMessagePartBody);

    if (result != KMsvMessagePartNone)
    {
    return EFalse;
    }

    // Validate recipient.
    result = iSmsMtm->ValidateMessage(KMsvMessagePartRecipient);

    if (result != KMsvMessagePartNone)
    {
    return EFalse;
    }

    return ETrue;
    }
    void CSmsHandler::ScheduleL()
    {
    CMsvEntrySelection* selection = new (ELeave) CMsvEntrySelection;
    CleanupStack::PushL(selection);
    selection->AppendL(iSmsMtm->Entry().EntryId()); // add message to selection

    // Add entry to task scheduler.
    TBuf8<1> dummyParams; // dummy parameters needed for InvokeAsyncFunctionL
    iOperation = iSmsMtm->InvokeAsyncFunctionL(ESmsMtmCommandScheduleCopy,
    *selection, dummyParams, iStatus);

    CleanupStack::PopAndDestroy(selection);

    iState = EWaitingForScheduling;
    SetActive();
    }
    [/CODE]

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

    Re: Incoming SMS notification

    In fact you can observe the Inbox in the emulator too: if you "Send" an SMS (first time you should do that from the built-in Messages application, because you are going to be asked about the SMSC - specify any number you like), a file (messagex.sms or something) will appear in epoc32\winscw\c\smsout. Copy it to smsin, the file will suddenly disappear, and you will get an incoming SMS in the Inbox.

    I just noticed that you apparently do not use "KObservedFolderId", so just try the above mentioned steps without modifying the code, and it may already work.

  3. #3
    Regular Contributor
    Join Date
    Oct 2008
    Location
    Bangalore,India
    Posts
    129

    Re: Incoming SMS notification

    Hi wizard_hu_ ,

    I got sms in inbox without doing anything.

    But the problem is i didn't get any notification in my application.

    i just called like this
    Code:
    TBuf<128> SMSText, PhoneNumber;
    				SMSText.Copy(_L("Test Message"));
    				PhoneNumber.Copy(_L("+911234567890"));// but ihave used this number...for my later use i have mentioned
    				iSmsHandler->SendL(PhoneNumber, SMSText);
    Last edited by kusumat; 2009-09-14 at 11:18. Reason: incorrect code

  4. #4
    Registered User
    Join Date
    Feb 2009
    Posts
    10

    Re: Incoming SMS notification

    Hi.. everyone
    i think i have the same problem too..
    even if our code is slightly different

    Code:
    //from sms engine   
    		 case EMsvEntriesCreated:
    			 {
    		            // Only look for changes in the Inbox KMsvGlobalInBoxIndexEntryId /draft KMsvDraftEntryId  
    		            if (aArg2 &&  *(static_cast<TMsvId*>(aArg2)) == KMsvGlobalInBoxIndexEntryId)
    		                {
    		                CMsvEntrySelection* entries =  static_cast<CMsvEntrySelection*>(aArg1);
    		                if( entries->Count() >= 1 )
    		                    {
    		                    iNewMessageId = entries->At(0);
    		                    }
    		                else
    		                    {
    					//Panic(ESmsEngineInternal);
    		                    }
    		                }
    		            break;
    			 } 
    			 
    		 case EMsvEntriesChanged: 
    			 {
    			// RDebug::Print(_L("DEBUG entries change +1"),__LINE__);
    			 if (aArg2 &&  *(static_cast<TMsvId*>(aArg2)) == KMsvGlobalInBoxIndexEntryId )
    				 {
    					 CMsvEntrySelection* entries = static_cast<CMsvEntrySelection*>(aArg1);
    					 if( entries->Count() < 1 )
    					     { 
    					       // RDebug::Print(_L("DEBUG ERROR!!! Panic(ESmsEngineInternal)"), __LINE__);
    					     }
    					 else if (iNewMessageId == entries->At(0))
    					     {  
    					    	RDebug::Print(_L("DEBUG entries KUidMsgTypeSMS %d"), KUidMsgTypeSMS);
    						RDebug::Print(_L("DEBUG entries iSession->GetEntryL %d"), ( iSession->GetEntryL( iNewMessageId ) )->Entry().iMtm );
    					   
    						 if ( ( iSession->GetEntryL( iNewMessageId /*entries->At( 0 )*/ ) )
    					    		 ->Entry().iMtm == KUidMsgTypeSMS )
    					    	 {   
    							 
    						     //it doesnt go here			
    					    	     iSelection->AppendL( iNewMessageId, 1 ); 
    					    	     ReadNewEntry(iNewMessageId);
    					    	 }
    					     } 
    				 }
    		 		              
    		 		  break; 
    		    }

    I tried what wizard suggested and i was able to make it work on symbian 3rd edition FP1.. the new entry was logged on text file
    but when i switch it up to FP2.. the code doesnt work..
    i tried to debug it per line and it turns out the new entry message type number is different with KUidMsgTypeSMS . . i dont know, maybe something wrong with this code

    Please.. help us out masters
    thanx

  5. #5
    Nokia Developer Champion
    Join Date
    Mar 2006
    Location
    Helsinki, Finland
    Posts
    8,345

    Re: Incoming SMS notification

    Quote Originally Posted by pemai23 View Post
    Hi.. everyone
    i tried to debug it per line and it turns out the new entry message type number is different with KUidMsgTypeSMS . . i dont know, maybe something wrong with this code
    Try to handle EMsvEntriesCreated case which will be triggered when there is a new entry in the messaging server. See this article where you would find SmsHander for S60 3rd.Zip and see the implementation of HandleSessionEventL. SMS Operations
    Nokia Developer Wiki Moderation team

  6. #6
    Registered User
    Join Date
    Feb 2009
    Posts
    10

    Re: Incoming SMS notification

    Correction..
    i'm sorry that code works on FP2 too..
    i reopened carbide and it works just fine..
    thank you so much wizard_hu

  7. #7
    Registered User
    Join Date
    Feb 2009
    Posts
    10

    Re: Incoming SMS notification

    Hi.. again
    sorry.. i got problem T_T
    the HandleSessionEventL code works on the emulator
    once i tried it on device..
    the application will be terminated automatically when the incoming message's received..
    Could you Give me some lights about the possible problem..

    thanx

  8. #8
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,694

    Re: Incoming SMS notification

    Enable the error messages as a first step: http://wiki.forum.nokia.com/index.ph...ded_panic_code - the last line of the section about S60 3rd edition contains a downloadable installer.

  9. #9
    Registered User
    Join Date
    Feb 2009
    Posts
    10

    Re: Incoming SMS notification

    hi wizard..
    thank u for reply..
    here's what i got from Panic Observer


    Panic details
    Time: 1:50:52 am - 3/10/2009
    Process: prototype[e4fb6530]
    0001
    Thread: prototype
    Category: E32USER-CBase
    Reason:21


    error desc "This panic is raised by any operation which accesses an element of an array by explicit reference to an index number, for example, the Delete(), InsertL() and At() member functions or the operator Operator[]. It is caused by specifying an index value which is either negative or is greater than or equal to the number of objects currently within the array.".


    here's the code..
    Code:
    void CSmsHandler::HandleSessionEventL( TMsvSessionEvent aEvent,
                                          TAny* aArg1, TAny* aArg2, TAny* /*aArg3*/)
    	{ 
    	switch ( aEvent )
    		{ 
    		case EMsvServerReady:
                {
                RDebug::Print(_L("DEBUG ON Server ready line %d"), __LINE__);
                TMsvId serviceId( KUidMsgTypeSMS.iUid ); // SMS service id
    
                // Determine if the event was succesful.
                // ServiceProgress inserts TBuf8 value in progress.
                TBuf8<KBfrLength> progress;
    			iSession->ServiceProgress( serviceId, progress );
    			_LIT8( KCompare, "KErrNone" );
    
    			if ( progress.Compare( KCompare ) )
    				{
                    // Check that MtmRegistry has not already been accessed.
                    if ( !iMtmRegistry )
                        {
    						AccessMtmL();
                        }
                    }
                break;
                }
                 
             //from sms engine   
    		 case EMsvEntriesCreated:
    			 {
    		           
    		            if (aArg2 &&  *(static_cast<TMsvId*>(aArg2)) == KMsvDraftEntryId)
    		                {
    		                CMsvEntrySelection* entries =  static_cast<CMsvEntrySelection*>(aArg1);
    		                if( entries->Count() >= 1 )
    		                    {
    								iNewMessageId = entries->At(0);
    		                    }
    		                else
    		                    {
    								//Panic(ESmsEngineInternal);
    		                    }
    		                }
    		            else if (aArg2 &&  *(static_cast<TMsvId*>(aArg2)) == KMsvGlobalInBoxIndexEntryId)
    		            	{
    		            		CMsvEntrySelection* entries =  static_cast<CMsvEntrySelection*>(aArg1);
    		            		 if( entries->Count() >= 1 )
    		            		    {
    		            				iNewMessageId = entries->At(0);
    		            		    }
    		            		else
    		            		    {
    		            				//Pan--ic(ESmsEngineInternal);
    		            		    }
    		            	}
    		            break;
    			 } 
    			 
    		 case EMsvEntriesChanged:  
    			 {
    			 if (aArg2 &&  *(static_cast<TMsvId*>(aArg2)) == KMsvGlobalInBoxIndexEntryId )
    				 {
    					 CMsvEntrySelection* entries = static_cast<CMsvEntrySelection*>(aArg1);
    					 if( entries->Count() < 1 )
    					     { 
    					        RDebug::Print(_L("DEBUG ERROR!!! Panic(ESmsEngineInternal)%d"), __LINE__);
    					     }
    					 else if (iNewMessageId == entries->At(0))
    					     {  
    					     if ( ( iSession->GetEntryL( iNewMessageId ) )->Entry().iMtm == KUidMsgTypeSMS )
    					    	 {   				     
    					    	     iSelection->AppendL( iNewMessageId, 1 ); 
    					    	     ReadNewEntry(iNewMessageId,1);
    		 			    	 }
    					     } 
    				 }
    		 		              
    		 		  break; 
    		    }
    could u tell me where it might be the error? because it works fine on the emulator..

    Thanx

  10. #10
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,694

    Re: Incoming SMS notification

    It is hard to guess, I think that "entries" always has an element; I usually do not even check. Consider making friends with On-Device Debugging. You can find various related resources in the Wiki, including screencasts for example.

Similar Threads

  1. notification of incoming call receiving, SMS and e-mail
    By silverrocha in forum [Archived] Flash Lite on Nokia Devices
    Replies: 5
    Last Post: 2009-07-04, 14:57
  2. Turning off incoming SMS notification programmatically
    By juannoguera in forum Symbian User Interface
    Replies: 3
    Last Post: 2009-03-05, 20:49
  3. Struggling to sound an alert on incoming SMS
    By colin@icrsystems.co.uk in forum Symbian
    Replies: 3
    Last Post: 2007-07-08, 18:01
  4. SMS Spec info plz for MMS Notification
    By muralimohank in forum General Messaging
    Replies: 2
    Last Post: 2003-05-28, 13:08

Posting Permissions

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