这在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();
结果应该看起来像这样:
,但实际上它只是一个普通的提示通知,如下所示(不像需要保持响铃直到您解除或打盹的那种):
。就像我提到的,我可以在Windows平板电脑(Windows 8.1)上很好地运行它,效果大致如下:
。编辑:值得注意的是,如果您的平板设备没有将您的应用程序指定为默认闹钟应用程序,则您将不会获得打盹/忽略按钮(只能有一个应用程序被指定为默认闹钟应用程序)。但是,在Windows Phone 8.1中,没有定义默认闹钟应用程序可以是什么的选项。