Здравствуйте, нужно сохранить все входящие смс в файл. Делаю так -
По сути это пример из вики.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); }
В итоге из 42-х смсок сохраняет только две, в остальных 40 случаях функция entry->ReadStoreL() возвращает -1.
Из library:
В чём юмор? Смски-то вроде как все одинаковые.KErrNotFound - There is no store associated with this entry
Зы. По форуму искал, но не нашёл


Reply With Quote

