如何在uwp应用程序中使用交互式通知



我有一个文件,里面有我的班级提醒。在适当的时候我收到通知。我使用NotificationExtension 创建通知

    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?如何获取?

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

首先获取提醒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,
            }
        }
    },
};

然后,您可以通过参数:在后台任务中获得提醒Id

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

最新更新