CMsvEntry::ReadStoreL KErrNotFound
Здравствуйте, нужно сохранить все входящие смс в файл. Делаю так -
[code]void CSMSUtils::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();
__LOGSTR1("EntryCount: %d",msgCount);
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;
/* Skip loop if fail in obtains the message store */
TRAPD(r, inboxStore = entry->ReadStoreL());
if(KErrNone != r)
{
__LOGSTR("r!=KErrNone");
CleanupStack::PopAndDestroy(entry);
continue;
}
CleanupStack::PushL(inboxStore);
__LOGSTR2("Count: %d, HasBodyText: %d",i,inboxStore->HasBodyTextL());
if (inboxStore->HasBodyTextL())
{
TMsvEntry entry1 = entry->Entry();
/* Gives you phone Number or Contact Name if Contact is present*/
TBufC<50>text(entry1.iDetails);
TBuf16<30> msg;
msg.Copy(_L("Name: "));
msg.Append(text);
/*If you want to get the Recipient Number, when iDetails gives you Contact's Name. */
iSmsMtm->LoadMessageL();
CSmsHeader& header = iSmsMtm->SmsHeader();
/* This will give you actual phone number irrespective of the name of contact*/
TPtrC from = header.FromAddress();
TBuf8<60> number;
number.Copy(_L("Number: "));
number.Append(from);
/* To read phone number from Sent Item folder, see the Note below */
CRichText& richText= iSmsMtm->Body();
inboxStore->RestoreBodyTextL(richText);
const TInt length = richText.DocumentLength();
/* Gives you actual content(Body) of SMS */
SMSContent->Des().Copy(richText.Read(0,length));
richText.Reset();
SMSContent8->Des().Copy(SMSContent->Des());
/* Write SMS Body in the SMSBody.txt file*/
//WriteToFile(SMSContent8->Des());
/* Write SMS Body, number and contact name in file*/
WriteToFile(msg, number,SMSContent8->Des());
}
else
{
// no text in SMS
}
CleanupStack::PopAndDestroy(2,entry);
}
CleanupStack::PopAndDestroy(4,SMSContent);
}[/code]
По сути это пример из вики.
В итоге из 42-х смсок сохраняет только две, в остальных 40 случаях функция entry->ReadStoreL() возвращает -1.
Из library:
[quote]KErrNotFound - There is no store associated with this entry [/quote]
В чём юмор? Смски-то вроде как все одинаковые.
Зы. По форуму искал, но не нашёл
Re: CMsvEntry::ReadStoreL KErrNotFound
В принципе решил как-то так:
[code]
CMsvEntry* pMsvEntry = iSession->GetEntryL(KMsvGlobalInBoxIndexEntryId);
TBuf8<256> buf;
for(TInt i=0;i<pMsvEntry->Count();i++)
{
buf.Append((*pMsvEntry)[i].iDetails);
buf.Append((*pMsvEntry)[i].iDescription);
.......
}[/code]
Но ведь это не всё сообщение. Вопрос открыт в общем
Re: CMsvEntry::ReadStoreL KErrNotFound
Порядок действий примерно такой:
CMsvEntry *entry = iMsvSession->GetEntryL((*entries)[i]);
if (entry)
{
CleanupStack::PushL(entry);
if (entry->Entry().iMtm == KUidMsgTypeSms)
{
iSmsMtm->SwitchCurrentEntryL(entryID);
iSmsMtm->LoadMessageL();
iSmsMtm->SmsHeader().Message().Buffer(); // текст sms
iSmsMtm->SmsHeader().FromAddress();
}
CleanupStack::PopAndestroy(entry);
}
Писал по памяти, код может не заработать сразу.