1

我正在尝试使用最新的 API 收集 Windows Mobile 10 调用历史记录。我已为我的应用程序启用了所有可能的功能,但在运行此代码时仍然出现“访问被拒绝”错误:

var operation = PhoneCallHistoryManager.RequestStoreAsync(PhoneCallHistoryStoreAccessType.AppEntriesReadWrite);
operation.Completed = (o, ev) =>
{
    PhoneCallHistoryStore store = o.GetResults();
    PhoneCallHistoryEntryReader reader = store.GetEntryReader();

    var operation2 = reader.ReadBatchAsync();
    operation2.Completed = (o2, ev2) =>
    {
        IReadOnlyList<PhoneCallHistoryEntry> callsList = o2.GetResults();
        foreach (PhoneCallHistoryEntry entry in callsList)
        {
            // process calls here
        }
    };
};

我在执行第 4 行时收到以下错误消息:

An exception of type 'System.UnauthorizedAccessException' occurred in App1.exe but was not handled in user code

Additional information: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

我在 Visual Studio 2015 的移动模拟器上运行此代码。这是我用于该代码的代码: https ://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.calls.aspx

知道有什么问题吗?

4

1 回答 1

2

为了使上述代码正常工作并查看电话历史记录,需要添加以下内容:

1) 重述命名空间

xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"

2) 受限功能“phoneCallHistory”

<rescap:Capability Name="phoneCallHistory"/>

3) 将 PhoneCallHistoryAccessType 更改为 AllEntriesLimitedReadAndWrite。

var operation = PhoneCallHistoryManager.RequestStoreAsync(PhoneCallHistoryStoreAccessType.AllEntriesLimitedReadWrite);

感谢@RaymondChen 给了我正确的能力名称。

于 2015-08-28T07:57:33.707 回答