【问题标题】:Trigger the Alarm in Windows Phone 8.1 Universal Store App?在 Windows Phone 8.1 Universal Store App 中触发警报?
【发布时间】:2014-07-06 21:20:04
【问题描述】:

这似乎在 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();

结果应如下所示:

但它目前只是像这样定期发送 toast 通知(在您按需要关闭或打盹之前它不会一直响铃):

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

编辑:值得注意的是,如果您的平板设备没有将您的应用分配为默认警报应用(只能分配一个),您确实不会获得贪睡/关闭按钮。但是,在 Windows Phone 8.1 中,没有选项可以定义默认警报应用程序可以是什么。

【问题讨论】:

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


    【解决方案1】:

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

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

    有一段(第一个)叫做

    Windows Phone 8 中没有与 Windows Phone 商店等效的功能

    在里面,你可以看到

    警报和提醒

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多