×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    37

    Recipient number of SMS

    Hello,

    I would like to write an application that would display recipient number of an SMS. I am following ReadInbox() method in http://wiki.forum.nokia.com/index.php/SMS_Operations. I want to display telephone number, not contact name.

    However,
    Code:
    const CArrayPtrFlat<CSmsNumber>&  array = smsHeader.Recipients();
    returns empty array. Anyone can help?

  2. #2
    Nokia Developer Champion
    Join Date
    Mar 2006
    Location
    Helsinki, Finland
    Posts
    8,347

    Re: Recipient number of SMS

    Using CSmsHeader API, you can achieve this.

    Code:
    CSmsHeader& header = iSmsMtm->SmsHeader();
    TPtrC from = header.FromAddress(); // This will give you number, instead of name
    Nokia Developer Wiki Moderation team

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    37

    Re: Recipient number of SMS

    I have discovered that the code is working for KMsvSentEntryId but not for KMsvGlobalInBoxIndexEntryId.
    For KMsvGlobalInBoxIndexEntryId FromAddress() must be used . So example on that page has an error.

    Thanks for help!

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

    Re: Recipient number of SMS

    Kiran's example is about the sender, not the recipient anyway. It has been covered here before, getting the recipient (which is in fact the MSISDN of the device your app runs on) is not possible. If you are lucky the recipients array may be populated, then again, it may not. What you can do is check the incoming PDU's at socket level. If the service center includes the recipient(s) then your in luck.

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

    Re: Recipient number of SMS

    Quote Originally Posted by bart12 View Post
    I have discovered that the code is working for KMsvSentEntryId but not for KMsvGlobalInBoxIndexEntryId.
    For KMsvGlobalInBoxIndexEntryId FromAddress() must be used . So example on that page has an error.

    Thanks for help!
    Quote Originally Posted by lieuwe View Post
    Kiran's example is about the sender, not the recipient anyway. It has been covered here before, getting the recipient (which is in fact the MSISDN of the device your app runs on) is not possible. If you are lucky the recipients array may be populated, then again, it may not. What you can do is check the incoming PDU's at socket level. If the service center includes the recipient(s) then your in luck.
    I guess I misunderstood the original question. What I understood is:

    1) Alice has mobile device.
    2) Bob sends message to Alice.
    3) Alice receives message from Bob in her inbox.
    4) Alice wants to retrieve the phone number of Bob from the message she just received(Or all messages in her inbox).
    5) Alice can retrieve phone number of Bob using FromAddress() from CSmsHeader class.

    Did I understand anything wrong?
    Nokia Developer Wiki Moderation team

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

    Re: Recipient number of SMS

    Or maybe I misunderstood, as he was talking about the SMSHeader->Recipients array I assumed the app was looking for the recipient, not the sender.

  7. #7
    Registered User
    Join Date
    Nov 2008
    Posts
    37

    Re: Recipient number of SMS

    I never wanted to get number of my phone since I know it may not be possible.
    I have written a method which is supposed to read Inbox (messages sent to my phone). It is more less the same as in the example's ReadInbox() method:
    Code:
    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 or Contact Name if Contact is present 			TBuf16<20> msg;
    			msg.Copy(aText);
                         
                             // If you want to get the Recipient Number, when iDetails gives you Contact's Name.
                            iSmsMtm->LoadMessageL();
    	                CSmsHeader& smsHeader = iSmsMtm->SmsHeader();
    	                const CArrayPtrFlat<CSmsNumber>&  array= smsHeader.Recipients();
    	                CSmsNumber* smsNumber = array.At(0);
    	                TPtrC RecipentNumber = smsNumber->Address();
                         // RecipentNumber will containt the recipent Number
    	             
     
    	
    			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);
    }
    However, it will not work because you cannot read smsHeader.Recipients() from messages sent to you (it will raise a panic).

    In order to get telephone number you have to use:
    smsHeader.Recipients() - for messages sent by the phone
    smsHeader.FromAddress() - for messages sent to your phone

    The example do has an error and that is the whole thing.

    Kiran, you understand well . Thanks for help both of you.

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

    Re: Recipient number of SMS

    Quote Originally Posted by bart12 View Post
    The example do has an error and that is the whole thing.
    I remember that somebody has added that code which you say is "not working". I didn't find time to verify that updated code. Anyways it would be nice of you if you can put working code in that article.

    Thanks.
    Nokia Developer Wiki Moderation team

  9. #9
    Super Contributor
    Join Date
    Mar 2004
    Location
    Bangalore,India
    Posts
    2,146

    Re: Recipient number of SMS

    Quote Originally Posted by bart12 View Post
    I never wanted to get number of my phone since I know it may not be possible.
    Getting own number is possible using API's that are available with the Binary Access Kit, so hopefully once Nokia decides to open them up as part of Symbian Foundation, that information should be out there in the open.

    Cheers,
    Mayank

  10. #10
    Regular Contributor
    Join Date
    Jun 2009
    Posts
    139

    Re: Recipient number of SMS

    Hi Bart12,

    I want only phone number from incoming sms not contact name.If you have solved this problem .Can you please share me the code ?I tried all the examples in wiki.But I didn't get the solution.I tried CSMSHeader::FromAddress() which is returning blank descriptor. TMsvEntry.Entry::iDetails returns contact name if phone number is saved in contacts application.

    Thanks in advance.
    J.Ramesh.

  11. #11
    Registered User
    Join Date
    Nov 2008
    Posts
    37

    Re: Recipient number of SMS

    Hi!

    CSMSHeader is working properly for this purpose. You have to remember that you can obtain the number using
    - FromAddress() for INBOX
    - Recipients() for OUTBOX, DRAFTS and SENT boxes.

    You will not be able to obtain your own number.

    Here is the code (function for reading SMS, CMessageSMS is a class created by me to represent individual SMS)
    You have to specify proper box in arguments:

    Code:
    	/**
    	 * use:
    	 * ********TMsvId********
    	 * KMsvGlobalInBoxIndexEntryId - inbox
    	 * KMsvGlobalOutBoxIndexEntryId - outbox
    	 * KMsvDraftEntryId - drafts
    	 * KMsvSentEntryId - sent
    	 * 
    	 */
    
    RPointerArray<CMessageSMS> CMessageHandlerEngine::ReadSMSFromBoxL(TMsvId aMsvId)
    	{
    	iBoxId = aMsvId; 
    	RPointerArray<CMessageSMS> array(10);
    	CleanupResetAndDestroyPushL(array);
    	
    	TMsvSelectionOrdering sort;
    	sort.SetShowInvisibleEntries(ETrue);
    	
    	CMsvEntry* boxContext=CMsvEntry::NewL(*iSession,aMsvId,sort); // Reading Messages from box Folder
    	CleanupStack::PushL(boxContext);
    
    	CMsvEntrySelection* entries = boxContext->ChildrenWithMtmL(KUidMsgTypeSMS);
    	CleanupStack::PushL( entries );
    
    	TInt msgCount= entries->Count();
    
    	for (TInt i=0; i < msgCount; i++)
    		{
    		TMsvId entryID = entries->At(i);
    
    		CMsvEntry* entry = iSession->GetEntryL((*entries)[i]);
    		const TMsvEntry& en = entry->Entry();
    
    		CleanupStack::PushL(entry);
    		iSmsMtm->SwitchCurrentEntryL(entryID);
    
    		CMsvStore* boxStore = entry->ReadStoreL();
    
    		CleanupStack::PushL(boxStore);
    		if (boxStore->HasBodyTextL())
    			{
    			CMessageSMS* message = CMessageSMS::NewLC();
    			
    			message->iMsvId = entryID;
    			message->iContactName.Des().Copy(en.iDetails);//Gives you phone Number or Contact Name if Contact is present
    			message->iUnread = en.Unread();	
    			message->iDate = en.iDate;
    				
    			// If you want to get the Recipient Number, when iDetails gives you Contact's Name.
    			iSmsMtm->LoadMessageL();
    			CSmsHeader& smsHeader = iSmsMtm->SmsHeader();
    				
    			switch (aMsvId)
    				{
    				case KMsvGlobalInBoxIndexEntryId:
    					{
    					message->iTelephoneNumber.Des().Copy(smsHeader.FromAddress()); 
    					}
    					break;
    				case KMsvGlobalOutBoxIndexEntryId:
    				case KMsvDraftEntryId:
    				case KMsvSentEntryId:
    					const CArrayPtrFlat<CSmsNumber>&  array= smsHeader.Recipients();
    					if (array.Count() > 0)
    						{
    						CSmsNumber* smsNumber = array.At(0);
    						message->iTelephoneNumber.Des().Copy(smsNumber->Address());
    						}
    					break;
    				}
    		
    			CRichText& richText= iSmsMtm->Body();
    			boxStore->RestoreBodyTextL(richText);
    			const TInt length = richText.DocumentLength();
    			
    		
    			message->iBody.Des().Copy(richText.Read(0,length)); // Gives you actual content(Body) of SMS
    			richText.Reset();
    			CleanupStack::Pop(message);
    			array.Append(message);
    			}
    		else
    			{
    			// no text in SMS
    			}
    		CleanupStack::PopAndDestroy(2,entry); //boxstore entry
    
    		}
    	CleanupStack::PopAndDestroy(2,boxContext);
    	CleanupStack::Pop(&array);
    	return array;
    	}

Similar Threads

  1. Need urgent help with incoming sms number.
    By Donnieng in forum Symbian
    Replies: 1
    Last Post: 2007-06-16, 05:52
  2. Replies: 2
    Last Post: 2007-02-02, 05:57
  3. How to get sms sender number?
    By cars2003 in forum Symbian
    Replies: 1
    Last Post: 2005-05-12, 12:15
  4. Replies: 1
    Last Post: 2003-09-15, 02:29

Posting Permissions

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