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]

oCancel()




