Can I create an alarm app for Window Universal App? - c#

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
There is now a way to create an alarm/reminder in universal windows
apps;
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);
The alarm/reminder supports vibrate only (just like toast) that can
be overwritten by user to turn off vibration;
The alarm/reminder supports a good level of customizability (custom
optional inline image, custom additional actions, etc).
Some references
Adaptive and interactive toast notifications for Windows 10
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 to automatically handle time conversion when time-zone changes (Workaround – this can be done by the app manually by using the TimeZoneChange system trigger);
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)).

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.

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.

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

Related

Xamarin android relaunch completely closed app at specific time - Android Version 10.0

I implement this functionality at previous Android versions and its work without any problem until version 10
This is my code:
[BroadcastReceiver(Enabled = true, Exported = false)]
public class Alarm : BroadcastReceiver
{
public async override void OnReceive(Context context, Intent intent)
{
PowerManager pm = (PowerManager)context.GetSystemService(Context.PowerService);
PowerManager.WakeLock wl = pm.NewWakeLock(WakeLockFlags.Partial, "");
wl.Acquire();
Vibrator v = (Vibrator)context.GetSystemService(Context.VibratorService);
v.Vibrate(800);
var audio = new AudioService();
await audio.PlayMp3File("1");
Intent i = new Intent(context, typeof(MainActivity));
i.AddFlags(ActivityFlags.NewTask);
context.StartActivity(i);
}
}
At version 10.0 the device play the MP3 Audio without launch the application
I could not find solution for this but I quote this from Wikipedia
Privacy and security
Several major security and privacy changes are present in Android 10:
........... There are
also new restrictions on the launching of activities by background
apps.For security (due to its use by clickjacking malware) and
performance reasons, Android 10 Go Edition forbids use of overlays,
except for apps that received the permission before a device was
upgraded to Android 10.
Is there any solution or it dismissed ?
It is now recommended by Google to use a notification as a prompt to launch your application from the "background".
i.e. The user must be involved the decision to launch an application
In nearly all cases, apps that are in the background should display time-sensitive notifications to provide urgent information to the user instead of directly starting an activity. Examples of when to use such notifications include handling an incoming phone call or an active alarm clock.
Google has a complete doc that covers when & how Android10 handles it now:
Restrictions on starting activities from the background

Background task registration hangs in UWP with GattCharacteristicNotificationTrigger

I'm trying to use an in-process background task to get notifications of a Bluetooth LE device. However, the following code hangs at the last line and does not return:
var bldr = new BackgroundTaskBuilder();
bldr.Name = guid.ToString("N");
var trigger = new GattCharacteristicNotificationTrigger(ch);
bldr.SetTrigger(trigger);
bldr.Register();
Getting the notifications of the device works when using the event-based model in the application. Also, registering the task with a TimeTrigger works, so the declaration in the app manifest is ok.
The computer runs the Creators Update, but the UWP is set to require the Anniversary update as a minimum.
We've had the same issue with UWP app on windows 10 mobile. It was resolved after we had updated windows 10 mobile to build 10.0.15230.0.
This hang on Register issue for GattCharacteristicNotificationTrigger was identified and fixed thanks to this question. The fix was released in build 15228 as a servicing build to the Creator's Update of the OS.

Windows 10 Feedback Task for my App

Similar to this question which invokes the Windows 10 store to allow a user to write a review or rate an app, I'd also like to be able to invoke the Windows 10 Feedback app and allow users to provide feedback there.
I cannot seem to find much information on:
How this works in general. Can any old app use this service? (I
notice it just kind of shows whatever apps I have running)
How to invoke the Windows Feedback app with my package id
In short - not that I can see.
Other apps are invoked via protocol activation. I haven't seen this documented for the feedback app though so I have to err on the side of 'we haven't made this available yet' (I'm still checking though)
Here's an overall guide to the process http://blog.jerrynixon.com/2012/10/walkthrough-using-windows-8-custom.html?m=1
When I look in the registry under HKEY_CLASSES_ROOT\Extensions\ContractId\Windows.Protocol I see (shortened a tad)
[HKEY_CLASSES_ROOT\Extensions\ContractId\Windows.Protocol\PackageId\Microsoft.WindowsFeedback...\ActivatableClassId\App.AppX7eaybq6p4x7d4jgd6w6jk7r5dg6yhmbf.mca\CustomProperties]
"Name"="windows-feedback"
So - give that a try via launching windows-feedback
If I do Windows Key-R (run): windows-feedback://
it works fine so this should work:
var uri = new Uri(#"windows-feedback://");
var success = await Windows.System.Launcher.LaunchUriAsync(uri);
if (success)
{
// URI launched
}
else
{
// URI launch failed
}
Update
I've done some searching and it seems the magic parameter there is
windows-feedback:?contextid=522
That launches the NFL feedback for example. This is a predetermined number - I'm not sure how one gets on this list though.

Audio Streaming in windows phone app (no Silverlight)

I am trying to play an audio stream from stream server in my windows phone app. I read on Microsoft Documentation that I have to reference an Audio Stream Agent.
I have these projects in my solution :
I've tried to reference a new project as Audio Streaming Agent in my Windows Phone 8.1 application
but I keeping receiving the error :
I read that I have to change the target framework, but there is no option for target framework in the AudioStreamAgent1 properties.
Also, Can I do this using an application that is not the Silverlight kind? Is there a way to do without using the Silverlight one?
The problem is that the AudioSteamAgent is targeted at WP Silverlight, and your actual app is WP8.1 (WinRT).
To create background audio in WP8.1, you will want to use the Background Media Player.
You can find a great guide for how to get started here.
But basically (without all the boilerplate code to wire everything up), it comes down to telling the BMP what to play (code is from the link above):
BackgroundMediaPlayer.Current.SetUriSource(new Uri("ms-appx:///Assets/Media/Ring02.wma"));
BackgroundMediaPlayer.Current.Play();
And telling the OS player controls what to show, and what to do when the user interacts with them:
systemmediatransportcontrol = SystemMediaTransportControls.GetForCurrentView();
systemmediatransportcontrol.ButtonPressed += systemmediatransportcontrol_ButtonPressed;
systemmediatransportcontrol.PropertyChanged += systemmediatransportcontrol_PropertyChanged;
systemmediatransportcontrol.IsEnabled = true;
systemmediatransportcontrol.IsPauseEnabled = true;
systemmediatransportcontrol.IsPlayEnabled = true;
systemmediatransportcontrol.IsNextEnabled = true;
systemmediatransportcontrol.IsPreviousEnabled = true;
This is all assuming that you want the user to be able to leave the app and have media continue to play. If you just want to stream audio/video while the user is in the app you can use the MediaElement control.

Hiding the Toast Notification when a push notification is received

I am using Windows azure push notifications. Every time a new notification is received a Toast is displayed with the information received, is there anyway I can disable this feature programmatically? The reason I want this is because I am trying to develop a FPS game and I am using the Push notifications to update locations, for obvious reasons I don't want the data received to get displayed.
You can hide the toast notification by setting the expiration time of the ToastNotification to DateTime.Now, that way it would expire as soon as it is displayed. You can do that by using the PushNotificationReceivedEventArgs args that is passed.
args.ToastNotification.ExpirationTime = DateTime.Now;
A better solution as provided by Gaurav is to use
args.Cancel=true;
What you could do is consume the PushNotificationReceived event and then handle it there. I did the same for one sample chat application I built. Look for the code for app.xaml.cs in my blog post here: http://gauravmantri.com/2012/08/30/how-i-built-an-awesome-chat-application-for-windows-8-with-windows-azure-mobile-service/.

Categories

Resources