UWP-Access被拒绝。 (来自HRESULT的异常:0x80070005(E_ACCESSDENIED))在Windows.ApplicationModel.Background.BackgroundTaskBuilder.Register()

时间:2017-10-29 03:04:13

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

使用

时出现异常
BackgroundTaskRegistration taskRegistration = taskBuilder.Register();

例外:

  

访问被拒绝。 (来自HRESULT的异常:0x80070005(E_ACCESSDENIED))在Windows.ApplicationModel.Background.BackgroundTaskBuilder.Register()

我的代码段

BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder();
SmsMessageReceivedTrigger trigger = new SmsMessageReceivedTrigger(filterRules);
taskBuilder.SetTrigger(trigger);
taskBuilder.TaskEntryPoint = "SmsBackgroundTask.SampleSmsBackgroundTask";
taskBuilder.Name = "SampleSmsBackgroundTask";
BackgroundTaskRegistration taskRegistration = taskBuilder.Register();

appxmanifest:

<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" 
         xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" 
         xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" 
         xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" 
         IgnorableNamespaces="uap mp rescap">`

  <Capabilities>
    <Capability Name="internetClient" />
    <rescap:Capability Name="cellularMessaging" />
  </Capabilities>

</Package>

<rescap:Capability Name="cellularMessaging" />

也有警告

警告:

  

命名空间“http://schemas.microsoft.com/appx/manifest/foundation/windows10”中的“功能”元素在命名空间“http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities”中具有无效的子元素“功能”

推荐this链接,用于创建后台任务。

0 个答案:

没有答案