/// <summary> /// Shows the toast notification. /// </summary> public async Task Show() { var builder = new ToastContentBuilder(); if (AppLogoOverride != null) { var uri = AppLogoOverride.GetSourceUri() ?? await AppLogoOverride.GetFileUriAsync().ConfigureAwait(false); builder.AddAppLogoOverride(uri); } // Title and Message are required. builder.AddText(Title, hintMaxLines: 1) .AddText(Message); builder.SetToastDuration(ToastDuration == ToastDuration.Short ? UwpNot.ToastDuration.Short : UwpNot.ToastDuration.Long); _tcs = new TaskCompletionSource <object>(); builder.Show(t => { TypedEventHandler <Windows.UI.Notifications.ToastNotification, ToastDismissedEventArgs> handler = (sender, args) => { }; handler = (sender, args) => { sender.Dismissed -= handler; _tcs.SetResult(null); }; t.Dismissed += handler; }); await _tcs.Task; }
/// <summary> /// Shows a native Mac OS notification. /// </summary> public async Task Show() { // The deprecated NSUserNotification is the only one available on // Xamarin.Mac var notification = new NSUserNotification { Title = Title, InformativeText = Message }; if (AppLogoOverride != null) { // Just get stream for all cases, handling the ms-appx:// stuff is tricky. var str = await AppLogoOverride.GetDataUrlAsync().ConfigureAwait(false); int i = "data:;base64,".Length; str = str.Substring(i); var data = new NSData(str, NSDataBase64DecodingOptions.None); notification.ContentImage = new AppKit.NSImage(data); } var center = NSUserNotificationCenter.DefaultUserNotificationCenter; center.DeliverNotification(notification); }
/// <summary> /// Shows the toast notification. /// </summary> public async Task Show() { if (_manager == null) { _manager = await GetNotificationManager(); // Something bad happend. if (_manager == null) { throw new InvalidOperationException("Failed to get toast notification manager for unknown reasons."); } CreateNotificationChannel(); } var iconId = _application.ApplicationInfo.Icon; if (iconId == 0) { iconId = Android.Resource.Drawable.SymDefAppIcon; } NotificationCompat.Builder builder = new NotificationCompat.Builder(_activity, channelId) .SetContentTitle(Title) .SetContentText(Message) .SetSmallIcon(iconId); if (AppLogoOverride != null) { var stream = await AppLogoOverride.GetStreamAsync().ConfigureAwait(false); var bitmap = await BitmapFactory.DecodeStreamAsync(stream).ConfigureAwait(false); builder.SetLargeIcon(bitmap); } var notification = builder.Build(); _manager.Notify(notificationId, notification); }
internal Element_ToastBinding ConvertToElement() { Element_ToastBinding binding = new(ToastTemplateType.ToastGeneric) { BaseUri = BaseUri, AddImageQuery = AddImageQuery, Language = Language }; // Add children foreach (var child in Children) { var el = (IElement_ToastBindingChild)AdaptiveHelper.ConvertToElement(child); binding.Children.Add(el); } // Add attribution if (Attribution != null) { binding.Children.Add(Attribution.ConvertToElement()); } // If there's hero, add it if (HeroImage != null) { binding.Children.Add(HeroImage.ConvertToElement()); } // If there's app logo, add it if (AppLogoOverride != null) { binding.Children.Add(AppLogoOverride.ConvertToElement()); } return(binding); } }