我可以为 Window Universal App 创建闹钟应用吗? [英] Can I create an alarm app for Window Universal App?

查看:24
本文介绍了我可以为 Window Universal App 创建闹钟应用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个闹钟应用.

我找到了在后台操作计时器的方法.但是没有找到控制显示器电源的 API(我想在显示器电源关闭时打开显示器电源).

Windows 10(Windows 通用应用程序)是否没有足够的 API 来创建该应用程序?

解决方案

<小时>

更新

微软最近回应了我的一个 API 请求,我在此处发布内容,以便每个人都知道添加了哪些 API 以及哪些 API 尚未完成.

做了什么

  1. 现在有一种方法可以在通用窗口中创建警报/提醒应用程序;
  2. 闹钟/提醒支持自定义贪睡时间(您可以选择让系统处理小睡,或唤醒你的后台任务来做它手动);
  3. 闹钟/提醒仅支持振动(就像吐司一样)被用户覆盖以关闭振动;
  4. 警报/提醒支持良好的可定制性(自定义可选的内嵌图片、自定义附加操作等).

一些参考

我们 (MSFT) 所知道的缺失并希望在不久的将来提供支持

  1. 警报/提醒中的本机平台支持在时区更改时自动处理时间转换(解决方法 - 这可以由应用程序使用 TimeZoneChange 系统触发器手动完成)
  2. 本地平台支持重复事件的警报/提醒(解决方法 - 目前只能通过应用程序手动定期唤醒并提前重新安排一堆警报/提醒来完成);

  3. 本机平台支持从音乐库中选择一首歌曲作为闹钟/提醒的铃声(解决方法 - 这可以通过从音乐库中读取和复制文件来完成,然后使用保存/修改的应用程序包中的文件版本或应用程序数据作为铃声(toast 通知通过指向 appx 中的文件或 xml 负载中的 appdata 中的文件来支持自定义声音).

I would like to create an alarm app.

I found the way of operating a timer in the background. But APIs which control the power of the display were not found(I want to turn on the display's power when its power is off).

Doesn't Windows 10 (Windows Universal App) have enough APIs to create that app?

解决方案

Windows-universal-samples has recently been updated with a few new RTM samples including this one - Notifications.

As Alarm is also one type of notification, it's now built within a new toast notification framework in the Universal Windows Platform.

After you downloaded the source code from the Notification's link above, run it with Visual Studio 2015 RTM and then once the app is loaded, go to

toasts > scenarios > scenario: alarm

and you will see a fully functional alarm app (along with Reminder and a lot other samples).


Let's talk about code.

Basically, unlike in Windows Phone Silverlight, you can now customise the alarm popup a bit by specifying the xml payload like this (make sure the scenario is set to alarm)

<toast launch='args' scenario='alarm'>
    <visual>
        <binding template='ToastGeneric'>
            <text>Alarm</text>
            <text>Get up now!!</text>
        </binding>
    </visual>
    <actions>

        <action arguments = 'snooze'
                content = 'snooze' />

        <action arguments = 'dismiss'
                content = 'dismiss' />

    </actions>
</toast>

And then create an XmlDocument which loads the above xml string

var xmlString = @"//copy above xml here//";
var doc = new Windows.Data.Xml.Dom.XmlDocument();
doc.LoadXml(xmlString);

Then create a ToastNotification and trigger it with ToastNotificationManager-

var toast = new ToastNotification(doc);
ToastNotificationManager.CreateToastNotifier().Show(toast);

That's it! You will see an alarm popup like below.


Update

Microsoft recently responded to one of my API requests and I am posting the content here so everyone knows what APIs have been added and what are still outstanding.

What has been done

  1. There is now a way to create an alarm/reminder in universal windows apps;
  2. The alarm/reminder supports custom snooze time (you can choose to let system handle snooze, or wake up your background task to do it manually);
  3. The alarm/reminder supports vibrate only (just like toast) that can be overwritten by user to turn off vibration;
  4. The alarm/reminder supports a good level of customizability (custom optional inline image, custom additional actions, etc).

Some references

What we (MSFT) know that’s missing and hope to support in the near future

  1. Native platform support in alarm/reminder to automatically handle time conversion when time-zone changes (Workaround – this can be done by the app manually by using the TimeZoneChange system trigger);
  2. Native platform support in alarm/reminder for recurrence events (Workaround – this can currently only be done by the app manually periodically waking up and reschedule a bunch of alarms/reminders ahead of time);

  3. Native platform support to select a song from Music library as ring tone for alarm/reminder (Workaround – this can be done by reading and copying files from your music library, and then use the saved/modified version of the file in your app package or app data as the ring tone (toast notification supports custom sound by pointing to files in appx or appdata in the xml payload)).

这篇关于我可以为 Window Universal App 创建闹钟应用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆