在Windows Phone 8.1 Universal Store App中触发警报?

时间:2014-05-19 02:20:03

标签: c# windows-runtime windows-phone-8.1 win-universal-app

这似乎在Windows 8.1 Universal Store App中正常工作,但在Windows Phone 8.1 Universal Store App中却无法正常工作。这可以调整为适用于Windows手机吗?就像它对Windows平板电脑一样吗?

XML文件:

<toast duration="long" launch="alarm(eb6c47a8-e5e2-40d0-bc4e-3aa957f36484)">
    <visual>
        <binding template="ToastImageAndText04">
            <text id="1">Alarm App</text>
            <text id="2">Alarm Test</text>
            <text id="3">Time to wake up!</text>
        </binding>
    </visual>
    <audio loop="true" src="ms-winsoundevent:Notification.Looping.Alarm2" />
    <commands scenario="alarm">
        <command id="snooze" />
        <command id="dismiss" />
    </commands>
</toast>

通知类:

public class Notification
{
    public async Task CreateNotification()
    {
        StorageFolder storageFolder = Package.Current.InstalledLocation;
        var toast = await storageFolder.GetFileAsync("toast.xml");
        var xml = await FileIO.ReadTextAsync(toast);
        NotifyScheduled(xml);
    }

    private void NotifyScheduled(string toast, int delay = 5, int snooze = 300, int maxSnoozeCount = 3)
    {
        XmlDocument document = new XmlDocument();
        document.LoadXml(toast);

        var notifier = ToastNotificationManager.CreateToastNotifier();
        var scheduledToast = new ScheduledToastNotification(document, DateTime.Now.AddSeconds(delay), TimeSpan.FromSeconds(snooze), (uint)maxSnoozeCount);
        notifier.AddToSchedule(scheduledToast);
    }
}

并在Phone的xaml.cs页面中实现:

var note = new Notification();
note.CreateNotification();

结果应如下所示:
enter image description here

但它目前只是做这样的常规干杯通知(在你根据需要解除或暂停它之前,它不会一直响铃):
enter image description here

就像我提到的,我可以让它在Windows平板电脑(Windows 8.1)中正常工作,它看起来像这样:
enter image description here

编辑:值得注意的是,如果您的平板电脑设备没有将您的应用指定为默认闹钟应用,则获取暂停/取消按钮(只有一个指定)。但是,在Windows Phone 8.1中,没有选项可以定义默认警报应用程序。

1 个答案:

答案 0 :(得分:6)

不幸的是(因为我也需要闹钟),目前似乎不可能。

这是一篇关于Windows Phone 8.0和8.1中的功能的非常好的文章,以及它们如何映射以及可以在哪里执行的操作:http://msdn.microsoft.com/en-us/library/dn642486(v=vs.105).aspx

有一个名为

的部分(第一部分)
  

没有Windows Phone Store等效的Windows Phone 8功能

在其中,您可以看到

  

警报和提醒