Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I create an alarm app for Window Universal App?

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?

like image 802
Tank2005 Avatar asked Jul 31 '15 07:07

Tank2005


1 Answers

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. enter image description here


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)).

like image 89
Justin XL Avatar answered Sep 23 '22 15:09

Justin XL