2016-05-18 95 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; 
    } 
} 
相關問題