简体   繁体   中英

Retrieving calls history from Windows 10 app - Access denied error

I'm trying to collect the Windows Mobile 10 calls history by using the latest API. I have enabled all possible capabilities for my application, but still I'm getting "Access Denied" error while running this code:

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

I'm getting the following error message while doing line 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))

I'm running this code on Mobile Emulator in Visual Studio 2015. This is what I used for that code: https://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.calls.aspx

Any idea what can be wrong?

In order to make above code working and view phone call history, need to add the following things:

1) Rescap namespace

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

2) Restricted capability "phoneCallHistory"

<rescap:Capability Name="phoneCallHistory"/>

3) Change PhoneCallHistoryAccessType to AllEntriesLimitedReadAndWrite.

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

Thanks to @RaymondChen for giving me the proper capability name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM