How to increase the show time of toastNotification in uwp? - c#

I am creating application using scheduled Toast Notification. I want to increase the show time of the Notification. How can i set the time for display the notification. Is there any other option for this?

According to the documentation you can use the duration property of your Toast Notification XML to display it either for a short (7s) or long (25s) time:
<toast duration="long">
<visual ... />
</toast>
This attribute was introduced back in Windows 8 time-frame for specifying how long the toast notification stays on the screen – setting the value to “short” will make the notification display for  ~7 seconds and setting it to “long” will make the notification display for ~25 seconds.
In Windows 10, developers have the following options to keep the notification on screen for longer than standard length (~7 seconds):
Specifying scenario attribute (see description below) to “alarm” or “reminder” to persist the notification on screen until the user dismisses it. 
Specify duration attribute to “long” while making sure the scenario attribute is specified to “default” or unspecified. This will result in the legacy behavior of notification showing on screen for ~25 seconds. 
We do not recommend using this property unless you have a good reason to keep the notification up for ~25 seconds on screen. This attribute exists mainly for appCompat reason. 
Further you can create a reminder notification to keep it visible until the user interacts with:
<toast scenario="reminder">
<visual ... />
</toast>
Note as stated in the documentation:
Do not use this just for keeping your notification persistent on screen.

Related

Toast Notification with Scenario of Reminder not staying on screen

I've built a C# Winforms App in which I've included toast notifications. The notifications work fine. However, when I change the ToastScenario to Reminder, the toast does not stay on screen like the Micorsoft documentation says it should (Reminder A reminder notification. This will be displayed pre-expanded and stay on the user's screen till dismissed.). I have no problem setting the duration to short or long, but I want this notification to stay visible until I interact with it. This app is just for me, so there is no danger of bothering the end user with a notification that persists until they click it. Here is the code that creates my notification:
new ToastContentBuilder()
.AddText(line1)
.AddText(line2)
.AddText(line3)
.AddArgument("link", link)
.AddInlineImage(new Uri(image))
.AddAudio(new Uri("C:\\Windows\\Media\\Alarm10.wav"))
.SetBackgroundActivation()
.SetToastScenario(ToastScenario.Reminder)
.Show();
I'm running the app on Windows 11 Pro. Amy thoughts on how to make the notification stay visible instead of just disappearing into the notifications bar?
I think Reminders require a button (an action that dismisses the toast). I added a button to my Toast and now it persists until the button is clicked. Like this:
new ToastContentBuilder()
.SetToastScenario(ToastScenario.Reminder)
.AddText(line1)
.AddText(line2)
.AddText(line3)
.AddButton(new ToastButton()
.SetContent("View")
.AddArgument("link", link)
.SetBackgroundActivation())
.AddInlineImage(new Uri(image))
.AddAudio(new Uri("C:\\Windows\\Media\\Alarm10.wav"))
.Show();

.NET NotifyIcon displays a toast notification twice in Windows 10

I use the .NET Framework System.Windows.Forms.NotifyIcon class to display a tray icon and tray notifications. When I call ShowBalloonTip on its instance, first the previously displayed notification displays again, then it hides, and only after a while does the expected one is displayed. It seems that historical notifications are displayed first unless I remove them manually from the notification center.
What can I do programmatically to prevent showing the historical notifications again?
Here's how I initialize the notify icon:
notifyIcon.Icon = Properties.Resources.tray_icon;
notifyIcon.Visible = true;
notifyIcon.BalloonTipTitle = Language.TrayMessageTitle;
Here's how I show the toast:
notifyIcon.BalloonTipIcon = icon;
notifyIcon.BalloonTipText = message;
notifyIcon.ShowBalloonTip(0);
The icon is either ToolTipIcon.Error or ToolTipIcon.Info, and I don't show a toast with the same icon twice, so they always toggle. But this does not seem to matter.
The timeout param is 0, because it's not used since Windows Vista.
The toast is displayed as a result of an application state change, not as a result of a user action like clicking.
So I decided to stick with disposing the notify icon instance and recreating it every time I display a toast notification. I don't think it's fine, but I couldn't find a better solution.
I also dispose the notify icon on application shutdown to clean the notification center from previously displayed notifications. Otherwise, the last one displays first when another application displays a toast.

How to achieve AlarmApplicationManager AlarmAccessStatus as AllowedWithWakeupCapability?

The AlarmApplicationManager provides a method RequestAccessAsync() to request permission from the user to be set as an alarm app. This seems to generate a dialog with Yes and No buttons. If the user taps on No, the value returned is Denied and when user taps Yes , the value seems to be AllowedWithoutWakeupCapability. But this link explains that it can return 4 values including AllowedWithWakeupCapability. How can I achieve AllowedWithWakeupCapability so that the device can wake up from sleep mode when alarm time is reached?

WinRT MediaElement: Detect changes from fullscreen to normal when IsFullWindow is true and AreTransportControlsEnabled is true

Context: WinRT, Universal Apps, XAML, C#
I am creating a video player application in which one of the requirements is that the video plays exclusively in fullscreen, and when the video returns from fullscreen, the video should be stopped and the user should be taken to a summary page. Currently I am using MediaElement.IsFullWindow and MediaElement.AreTransportControlsEnabled in order to play the video in fullscreen and it works perfectly well, when the video ends I grab the MediaEnded event and take the user back to the summary page, setting IsFullWindow to false and AreTransportControlsEnabled to false.
The only problem is that Transport Controls have a fullscreen button that takes the user back to the non-fullscreen layout and the video keeps on playing.
On most applications this would be great, but on this one, I need to stop the video when it happens.
Unfortunately, when this happens, IsFullWindow is not set to false, the SizeChanged event for the MediaElement is not fired and there seems to be no other notification that the user has decided to leave fullscreen mode.
So I am trapped in a situation in which I am unable to find out whether the video is truly playing in fullscreen or not.
If I pause the video and the user plays it again, since IsFullWindow is true, it will go back to fullscreen and if I let the video play to the end everything works fine and the user goes to the summary page.
Does anybody have any suggestions on how I may be able to detect this change in order to stop the video?
An alternative solution is not to use transport control provided by media element and create your own custom media controls .
See this MSDN link which explains how to create custom media transport controls
When changed IsFullWindow status fires SizeChanged of Window.Current instead of MediaElement. You just should attach to this event
Window.Current.SizeChanged += this.OnWindowSizeChanged;
and check IsFullWindow of MediaElement when it fired.
private void OnWindowSizeChanged(object sender, WindowSizeChangedEventArgs windowSizeChangedEventArgs)
{
if (!this.mediaElement.IsFullWindow)
{
}
else
{
}
}
I ended up using the Microsoft Player Framework which gives me events and properties to control all I needed without having to write my own code and incur in design work for the video player control assets.
You can overcome this issue by binding, IFullWindow MediaElement property with "TwoWay" mode, and act accordingly to its value on set :)
You may use a DispatcherTimer called every 100 ms, check the status of the IsFullWindow property, and if property value changes, fire an event or call your own function.

Disable next/prev buttons in Universal Volume Control (uvc) when using AudioPlayerAgent

I'm currently working on an radio app for WP7 Mango and I want to disable the next and the previous track buttons in the UVC like last.fm did in their app, but I can't figure out how.
Can someone help me with this?
You can select which controls are active in the UVC when you create the track to play in your agent (i.e. from the code which handles the TrackEnded event in the Background Audio Agent).
For example:
EnabledPlayerControls controls = EnabledPlayerControls.Pause |
EnabledPlayerControls.Rewind |
EnabledPlayerControls.FastForward;
AudioTrack track = new AudioTrack(
trackUri,
trackTitle,
trackBy,
trackAlbum,
trackAlbumArtUri,
trackTag,
controls);
...
return track
This will allow you to be able to make the agent skip tracks when your application wants, but Skip won't work by tapping the buttons on the UVC.
(In this example if the user taps and holds the fast-forward and rewind buttons in the UVC, the track will still fast-forward/rewind).
If you don't supply a entire playlist, but only a single MediaHistory , the Previous/Next buttons should be automatically disabled.
The same should apply to the AudioStreamingAgent. If you wish to disable the ability to use the buttons, handle the BackgroundAudioPlayer.Instance.PlayStateChanged event, see WP7 Mango: How to handle skip next/previous from UVC outside of the Audio Playback Agent class library? for details.
Post some code, if you want more detailed help.

Categories

Resources