Search code examples
uwpwin-universal-appwindows-10-mobile

Getting call history returns only last 20 logs


PhoneCallHistoryStore store = await PhoneCallHistoryManager.RequestStoreAsync(PhoneCallHistoryStoreAccessType.AllEntriesLimitedReadWrite);
PhoneCallHistoryEntryQueryOptions options = new PhoneCallHistoryEntryQueryOptions() { DesiredMedia = PhoneCallHistoryEntryQueryDesiredMedia.All };
PhoneCallHistoryEntryReader reader = store.GetEntryReader(options);
var logs = await reader.ReadBatchAsync();

Here logs.Count is always 20.

How can I get all the logs?


Solution

  • Yes, it's the correct behavior. In method's name you can see Batch. It means that you take part of calls (20 items). For getting all calls use the following code:

        PhoneCallHistoryStore store = await PhoneCallHistoryManager.RequestStoreAsync(PhoneCallHistoryStoreAccessType.AllEntriesLimitedReadWrite);
        PhoneCallHistoryEntryQueryOptions options = new PhoneCallHistoryEntryQueryOptions() { DesiredMedia = PhoneCallHistoryEntryQueryDesiredMedia.All };
        PhoneCallHistoryEntryReader reader = store.GetEntryReader(options);
        var phoneCallHistoryEntries = new List<PhoneCallHistoryEntry>();
    
        var hasItems = true;
        do
        {
            var logs = await reader.ReadBatchAsync();
            phoneCallHistoryEntries.AddRange(logs);
            hasItems = logs.Count > 0;
        }
        while (hasItems);