Reputation: 909
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?
Upvotes: 6
Views: 7918
Reputation: 39006
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.
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
Some references
Toast Notification and Action Center Overview for Windows 10
Quickstart: Sending a local toast notification and handling activations from it (Windows 10)
What we (MSFT) know that’s missing and hope to support in the near future
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);
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)).
Upvotes: 16
Reputation: 4605
There are a number of Win 10 Universal Samples on GitHub which may be useful. I didn't see anything directly related to Alarms, though.
Upvotes: 2
Reputation: 443
unfortunately Windows Universal Applications have no direct access to the Display Settings. But you can use the AlarmApplicationManager Class to create an Alarm. This will, in some cases (for sure on WindowsPhone) turn on the display automatically to show off the Alarm (with Title and Description).
Upvotes: 0
Reputation: 1493
AlarmApplicationManager
can be used to create alarm apps. It gives capabilities to schedule toast notifications.
var scheduledToast = new ScheduledToastNotification(content, DateTime.Now.AddMinutes(5));
toastNotifier.AddToSchedule(scheduledToast);
An audio source can also be set while creating the toast template, but only from a set of predefined sounds supplied by windows.
Refer AlarmApplicationManager and Building alarm app for more details.
Upvotes: 2