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();
Related
I have a Xamarin.Android app that shows lyrics from Genius and can detect music playing from the notifications.
In this app, the Main Activity contains a FrameLayout that is dynamically filled with a Welcome screen layout or a Song layout. The first is used when the user opens the app and no song has been detected, while the second appears when the user searches a song or opens the app through the notification sent when the app finds a song playing. Both the Welcome layout and the Song layout use ConstraintLayouts to display content.
This is how the layout looks without content:
Sometimes while loading the song, the layout size is not updated to fit the content inside the views. It has a loading wheel that is set to Gone when the lyrics finish loading.
Fully loaded, the screen should look like this:
However, it looks like this:
You can see that the broken layout is the same size and shape as it is on Android Studio.
The only thing I've been able to correlate with this bug is this LogCat message:
W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy#2bd3336
This message always appears when this bug happens, but not the other way around. Sometimes it appears but the bug does not happen.
From what I've googled, this is related to the notification opening another instance of the MainActivity. My testing suggests this as well since the OnCreate method is called even when the app is already opened and the notification is touched. I have not been able to get this bug to occur without opening the app through the notification.
Here's the code that created the notification:
private void CreateNotification(string title, string artist)
{
Log.WriteLine(LogPriority.Verbose, "NLService", "CreateNotification: Creating notification");
MainActivity.fromNotification = true;
TaskStackBuilder stackBuilder = TaskStackBuilder.Create(Application.Context);
stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(MainActivity)));
stackBuilder.AddNextIntent(new Intent(Application.Context, typeof(MainActivity)));
PendingIntent resultIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
.SetAutoCancel(true)
.SetContentTitle("SmartLyrics")
.SetContentText(artist + " - " + title)
.SetSmallIcon(Resource.Drawable.ic_stat_name)
.SetContentIntent(resultIntent)
.SetPriority(-1);
ntfManager = NotificationManagerCompat.From(Application.Context);
ntfManager.Notify(NOTIFICATION_ID, builder.Build());
Log.WriteLine(LogPriority.Info, "NLService", "CreateNotification (NLService): Notification made!");
}
I recorded my phone screen showing how it's behaving, first opening from the notification and then closing the app and opening the Song by searching from inside the app. Here's the LogCat for that session.
The whole project is open source, and the code is available here (the layout-testing branch is the one you should be looking at). Please spare me on how much this code is bad, I know about it and I'm slowly fixing stuff. This issue has been plaguing me for a long time and I want to get it fixed before working on other things.
Thanks in advance!
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.
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.
In my Windows phone application, when the message box is displayed and if the phone is rotated, only the message box is getting rotated, whereas the UI behind it remains in the previous orientation.
It seems like the "Orientation changed" event of the page is not getting triggered when the message box is being displayed.
Although the UI behind the message box is not so prominent, I could find that the native messaging app of windows phone follows this behavior. I mean if the message box is displayed and the orientation is changed, the list behind the message box is also changed.
This image is of the native messaging app.
This image is from my application
You can notice the list behind the both the images.
Can I get some help in achieving this behavior ?
MessageBox.Show(string msg) is a synchronized method, meaning the method won't return until you dismiss the message box by pushing one of its buttons. So UI thread is blocked, and the OrientationChanged is only handled after the message box is dismissed since the event handler is running on UI thread, too.
MessageDialog.ShowAsync, which is only available on Windows Phone 8.1, should not have this limitation.
One alternative to MessageBox is the Popup control. You can lay it on top of your page, and set it IsOpen to true/false to show/hide it. Make it look good on both Landscape and Portrait orientations using ViewStates, just like other normal controls.
I want to show a popup window for few seconds to greet users on their desktop.
it should be non-interactive.i want to do this in c# ,winform or wpf.
For example,
After user logged in, For every 3 hours , “Hello” message Should be shown for a second, then auto hide.
can anyone give some ideas.
thanks
In WPF:
Use Popup control to display your "Hello".
In the application, to set up recurring popup display and close, set up an instance of System.Windows.Threading.DispatcherTimer Class.
Create a form to display whatever message you want, size it however you feel. But a timer on it for 3 seconds that will do form.close() when the timer expires.
when your app loads, have it display the form.