获取呼叫历史记录仅返回最近20个日志

时间:2016-03-19 21:44:47

标签: uwp win-universal-app windows-10-mobile

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

此处logs.Count始终为20。

如何获取所有日志?

1 个答案:

答案 0 :(得分:2)

是的,这是正确的行为。在方法名称中,您可以看到Batch。这意味着你接听了一部分电话(20项)。要获取所有呼叫,请使用以下代码:

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