【问题标题】:How to schedule a local notification in windows phone app 8.1 rt?如何在 Windows Phone 应用程序 8.1 rt 中安排本地通知?
【发布时间】:2016-02-07 11:01:27
【问题描述】:

在我的应用程序中,我想为特定时间安排本地通知。

此本地通知也需要在应用关闭时发送。 (后台任务)

我使用的是 win RT,而不是 Silver Light。

提前谢谢你。

【问题讨论】:

  • 后台任务每隔 30 分钟左右触发一次。你可以试试这个。这足以满足您的需求吗?

标签: windows-phone-8 windows-phone-8.1 scheduled-tasks localnotification background-task


【解决方案1】:

你用过ScheduledToastNotification

以下示例显示了预定在一小时后显示的 Toast 通知。

var Notifications = Windows.UI.Notifications;
var currentTime = new Date();
var seconds = 60;
var dueTime = new Date(currentTime.getTime() + seconds * 60 * 1000);
var idNumber = Math.floor(Math.random() * 100000000);  // Generates a unique ID number for the notification.

// Set up the notification text.
var toastXml = Notifications.ToastNotificationManager.getTemplateContent(Notifications.ToastTemplateType.toastText02);
var strings = toastXml.getElementsByTagName("text");
strings[0].appendChild(toastXml.createTextNode(This is a scheduled toast notification));
strings[1].appendChild(toastXml.createTextNode("Received: " + dueTime.toLocaleTimeString()));

// Create the toast notification object.
var toast = new Notifications.ScheduledToastNotification(toastXml, dueTime);
toast.id = "Toast" + idNumber;

// Add to the schedule.
Notifications.ToastNotificationManager.createToastNotifier().addToSchedule(toast);

你必须使用dueTime和toast id

【讨论】:

    猜你喜欢
    • 2016-03-23
    • 2016-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多