2016-05-18 49 views
0

我有我的课堂提醒文件。在正确的时间我有通知。我创建NotificationExtension如何在uwp应用程序中工作交互式通知?

ToastContent content = new ToastContent() 
    { 
     Launch = "OrangeReminder", 

     Visual = new ToastVisual() 
     { 
      TitleText = new ToastText() 
      { 

       Text = "OrangeReminder" 
      }, 

      BodyTextLine1 = new ToastText() 
      { 
       Text = "" 
      }, 
      BodyTextLine2 = new ToastText() 
      { 
       Text = "" 
      }, 
     }, 
     Actions = new ToastActionsCustom() 
     { 
      Buttons = 
      { 
       new ToastButton("Done", "1") 
       { 
        ActivationType = ToastActivationType.Background, 
       } 
      } 
     }, 

    }; 

通知我创建后台任务

namespace BackgroundTasks 
{ 
public sealed class ToastNotificationBackgroundTask : IBackgroundTask 
{ 
    public void Run(IBackgroundTaskInstance taskInstance) 
    { 
     var details = taskInstance.TriggerDetails as ToastNotificationActionTriggerDetail; 
     var arguments = details.Argument; 
     //??? 
    } 

我在后台任务就写什么,从我的文件时,按下按钮在通知中删除提醒?我想我需要我的提醒ID?如何得到它?

+0

对于关于获取提醒ID的问题,我在下面发布了一个答案。获取提醒ID后,如何从文件中删除提醒?这个文件是什么意思?它是否放置在本地存储中?我对此有点好奇:) –

+0

我有收集文件“AllReminder.json”文件。我只是加载文件,加载收集并删除它“删除(GetRemObject)。 – SuxoiKorm

+0

我试试这个 if(arguments ==”1“) { LoadFile(); DS.AllRem.RemoveAt(1); } 但他没有工作,通知并没有消失,而且提醒也没有删除 – SuxoiKorm

回答

0

我在背景任务中写什么,在按钮按下通知时从我的文件中删除提醒?我想我需要我的提醒ID?如何得到它?

首先获得您的提醒标识,并将其设置到ToastContent的参数

// get your Reminder Id 
string reminderID = GetReminderID(); 

ToastContent content = new ToastContent() 
{ 
    ... 
    Actions = new ToastActionsCustom() 
    { 
     Buttons = 
     { 
      // set your Reminder ID into the Argument to pass it to the background task 
      new ToastButton("Done", reminderID) 
      { 
       ActivationType = ToastActivationType.Background, 
      } 
     } 
    }, 
}; 

然后你就可以通过参数让你的提醒标识在后台任务

public sealed class ToastNotificationBackgroundTask : IBackgroundTask 
{ 
    public void Run(IBackgroundTaskInstance taskInstance) 
    { 
     var details = taskInstance.TriggerDetails as ToastNotificationActionTriggerDetail; 
     // get your Reminder Id in Background task through the Argument 
     var reminderID = details.Argument; 
    } 
} 
相关问题