当手机有来电时,我需要做一些任务,但目前我不能。
我已经阅读了有关当无法识别的来电到达此链接CallerID时要触发的后台任务的示例,我已尝试过,但我的后台任务没有收到任何内容。
这是注册后台任务代码:
private async void RegisterTask()
{
string phoneObsName = "phoneObsName";
var access = await BackgroundExecutionManager.RequestAccessAsync();
if (access != BackgroundAccessStatus.Denied &&
access != BackgroundAccessStatus.Unspecified)
{
// Create a new background task builder.
BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder();
// Create a new Phone Trigger.
PhoneTrigger trigger = new PhoneTrigger(PhoneTriggerType.CallOriginDataRequest, false);
// Associate the phone trigger with the background task builder.
taskBuilder.SetTrigger(trigger);
// Specify the background task to run when the trigger fires.
taskBuilder.TaskEntryPoint = typeof(BackgroundStuff.PhoneCallBackgroundTask).ToString(); ;
// Name the background task.
taskBuilder.Name = phoneObsName;
// Register the background task.
BackgroundTaskRegistration taskRegistration = taskBuilder.Register();
//UpdateBackgroundTaskUIState(true);
//rootPage.NotifyUser("Registered Caller ID background task", NotifyType.StatusMessage);
}
else
{
//rootPage.NotifyUser("Background agent access denied", NotifyType.ErrorMessage);
}
}
请帮我解决问题。