Getting call history returns only last 20 logs

2019-07-20 15:22发布

问题:

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?

回答1:

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);