简体   繁体   English

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

[英]Trigger the Alarm in Windows Phone 8.1 Universal Store App?

This seems to work fine in Windows 8.1 Universal Store App but not in Windows Phone 8.1 Universal Store App. 这似乎在Windows 8.1 Universal Store App中正常工作,但在Windows Phone 8.1 Universal Store App中却没有。 Can this be tweaked to work for the Windows phone just like it does for the Windows tablet? 这可以调整为适用于Windows手机,就像它对Windows平板电脑一样吗?

XML FILE: 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>

Notification class: 通知类:

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

And implemented in the Phone's xaml.cs page: 并在Phone的xaml.cs页面中实现:

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

The results should look something like this: 结果应如下所示:
在此输入图像描述

but it currently just does a regular toast notification like this (which doesn't keep ring the alarm until you dismiss or snooze it like it needs to): 但它目前只是像这样做一个常规的吐司通知(在你根据需要解雇或打盹之前不会发出警报):
在此输入图像描述

Like I mentioned, I can get this to work fine in Windows tablet (Windows 8.1) and it looks something like this: 就像我提到的,我可以让它在Windows平板电脑(Windows 8.1)中正常工作,它看起来像这样:
在此输入图像描述

EDIT: it's notable to mention that you do not get the Snooze/Dismiss buttons if your tablet device does not have your app assigned as the default Alarm app (there can only be one assigned). 编辑:值得注意的是,如果您的平板电脑设备没有将您的应用程序指定为默认警报应用程序(只能分配一个),则不会显示 “暂停/关闭”按钮。 However, in Windows Phone 8.1, there is not an option to define what the default alarm app can be. 但是,在Windows Phone 8.1中,没有选项可以定义默认警报应用程序的内容。

Unfortunately (as I need alarms as well), it does not seem to be possible at the moment. 不幸的是(因为我也需要警报),目前似乎不可能。

Here's a very good article about features in Windows Phone 8.0 and 8.1 and how they map and what can be done where: http://msdn.microsoft.com/en-us/library/dn642486(v=vs.105).aspx 这是一篇关于Windows Phone 8.0和8.1中的功能以及它们如何映射以及可以在哪里完成的非常好的文章: http//msdn.microsoft.com/en-us/library/dn642486(v = vs.105).aspx

There's a section (the first one) called 有一节(第一节)叫

Windows Phone 8 features for which there is no Windows Phone Store equivalent Windows Phone 8功能,没有Windows Phone Store等效功能

In it, you can see 在其中,你可以看到

Alarms and reminders 警报和提醒

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM