×
Namespaces

Variants
Actions

Archived:Sending an SMS using Symbian C++

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Article Metadata
Code ExampleTested with
Devices(s): Nokia 6220 Classic
Compatibility
Platform(s): S60 3rd Edition; S60 3rd Edition, FP1; S60 3rd Edition, FP2; S60 5th Edition
Symbian
S60 3rd Edition FP2
Article
Keywords: RSendAs, RSendAsMessage, RSendAs::Connect(), RSendAsMessage::CreateL(), RSendAsMessage::AddRecipientL(), RSendAsMessage::SetBodyTextL(), RSendAsMessage::SendMessageAndCloseL()
Created: tapla (13 Feb 2009)
Last edited: hamishwillee (14 Jun 2013)

Contents

Overview

This code snippet demonstrates how to send an SMS using RSendAs and RSendAsMessage.

MMP file

The following library is required:

LIBRARY sendas2.lib

You may also want to add the following capability:

CAPABILITY NetworkServices

The capability is not required but without it the application asks for permission to send the message.

Header file

private:  // New methods
void SendSMSL();

Source file

#include <rsendas.h>
#include <rsendasmessage.h>
#include <smut.h>
void CAppUi::SendSMSL()
{
RSendAs sendAs;
TInt err = sendAs.Connect();
if (err) {
// TODO: Error handling
return;
}
CleanupClosePushL(sendAs);
 
RSendAsMessage sendAsMessage;
sendAsMessage.CreateL(sendAs, KUidMsgTypeSMS);
CleanupClosePushL(sendAsMessage);
 
// Add the receiver
_LIT(KReceiver, "+358123123123");
sendAsMessage.AddRecipientL(KReceiver, RSendAsMessage::ESendAsRecipientTo);
 
// Set the body text
_LIT(KBodyText, "Hello!");
sendAsMessage.SetBodyTextL(KBodyText);
 
// Send the message
sendAsMessage.SendMessageAndCloseL();
 
CleanupStack::Pop(); // sendAsMessage (already closed)
CleanupStack::PopAndDestroy(); // sendAs
 
_LIT(KInfoText, "Message sent.");
iAppView->LogPrintL(KInfoText);
}

Postconditions

The application sends an SMS to the number specified in the code.

Supplementary material

  • You can test SMS sending features in action in a simple, executable application into which this code snippet has been patched. The application is available for download at Media:ExampleStub w SMS sending.zip
  • You can examine all the changes that are required to implement SMS sending in an application. The changes are provided in unified diff and colour-coded diff formats: Media:Sending an SMS.diff.zip
  • For general information on applying the patch, see Using Diffs.
  • For unpatched stub applications, see Example stub.
This page was last modified on 14 June 2013, at 09:34.
78 page views in the last 30 days.