在Windows Phone 8.1通用商店应用中触发警报?

7

这在Windows 8.1通用应用商店中似乎可以正常工作,但在Windows手机 8.1通用应用商店中则不行。是否可以对其进行调整,使其能像在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);
    }
}

并在手机的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个回答

6
很不幸(因为我也需要闹钟),目前似乎不可能实现。这是一篇关于Windows Phone 8.0和8.1功能的很好的文章,它展示了这些功能之间的映射以及可以在哪里进行操作:http://msdn.microsoft.com/en-us/library/dn642486(v=vs.105).aspx。其中有一个叫做“没有Windows Phone商店等效项的Windows Phone 8功能”的部分,在其中您可以看到闹钟和提醒。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接