我尝试使用最新的API收集Windows Mobile 10通话记录。我为我的应用程序启用了所有可能的功能,但我仍然得到了#34;访问被拒绝"运行此代码时出错:
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中的Mobile Emulator上运行此代码。 这就是我用于该代码的内容: https://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.calls.aspx
知道什么是错的吗?
答案 0 :(得分:2)
为了使上述代码正常工作并查看电话通话记录,需要添加以下内容:
1)Rescap名称空间
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为我提供了正确的功能名称。