public static PushNotification FromNative(RemoteMessage message) { Notification?notification = null; var native = message.GetNotification(); if (native != null) { notification = new Notification { Title = native.Title, Message = native.Body, Channel = native.ChannelId }; if (!native.Icon.IsEmpty()) { notification.Android.SmallIconResourceName = native.Icon; } if (!native.Color.IsEmpty()) { notification.Android.ColorResourceName = native.Color; } } return(new PushNotification(message.Data, notification)); }
protected override PendingIntent CreateActionIntent(Notification notification, ChannelAction action) { var intent = this.Services.Android.CreateIntent <ShinyPushNotificationBroadcastReceiver>(ShinyPushNotificationBroadcastReceiver.EntryIntentAction); this.PopulateIntent(intent, notification); intent.PutExtra(INTENT_KEY, action.Identifier); counter++; var pendingIntent = PendingIntent.GetBroadcast( this.Services.Android.AppContext, counter, intent, PendingIntentFlags.UpdateCurrent ) !; return(pendingIntent); }
public override async void OnMessageReceived(RemoteMessage message) => await Log.SafeExecute(async() => { await ShinyHost.Container.RunDelegates <IPushDelegate>(x => x.OnReceived(message.Data)); this.msgBus.Value.Publish( nameof(ShinyFirebaseService), message.Data ); var native = message.GetNotification(); if (native != null) { var notification = new Notification { Title = native.Title, Message = native.Body, Category = native.ClickAction, //Sound = native.Sound, // recast this as implementation types aren't serializing well Payload = message.Data?.ToDictionary( x => x.Key, x => x.Value ) }; if (!native.ChannelId.IsEmpty()) { notification.Android.ChannelId = native.ChannelId; } if (!native.Icon.IsEmpty()) { notification.Android.SmallIconResourceName = native.Icon; } if (!native.Color.IsEmpty()) { notification.Android.ColorResourceName = native.Color; } // TODO: I have to intercept the response for the IPushDelegate.OnEntry await this.notifications.Value.Send(notification); } });
public override async void OnMessageReceived(RemoteMessage message) => await Log.SafeExecute(async() => { await this.pushDelegate.Value.OnReceived(message.Data); this.msgBus.Value.Publish( nameof(ShinyFirebaseService), message.Data ); var native = message.GetNotification(); if (native != null) { var notification = new Notification { Title = native.Title, Message = native.Body, Category = native.ClickAction, Payload = message.Data }; if (!native.ChannelId.IsEmpty()) { notification.Android.ChannelId = native.ChannelId; } if (!native.Icon.IsEmpty()) { notification.Android.SmallIconResourceName = native.Icon; } if (!native.Color.IsEmpty()) { notification.Android.ColorResourceName = native.Color; } await this.notifications.Value.Send(notification); } });
protected override void PopulateIntent(Intent intent, Notification notification) { var content = this.Services.Serializer.Serialize(notification); intent.PutExtra(INTENT_KEY, content); }
public static async Task <NotificationResult> RequestAccessAndSend(this INotificationManager notifications, Notification notification) { var access = await notifications.RequestAccess(); if (access != AccessState.Available) { return(NotificationResult.Fail(access)); } await notifications.Send(notification); return(NotificationResult.Success(notification.Id)); }