简体   繁体   中英

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. Can this be tweaked to work for the Windows phone just like it does for the Windows tablet?

XML FILE:

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

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:
在此输入图像描述

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.

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

There's a section (the first one) called

Windows Phone 8 features for which there is no Windows Phone Store equivalent

In it, you can see

Alarms and reminders

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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