Custom Push notification
Monikaprime opened this issue · 1 comments
Monikaprime commented
how can I have custom notification builder in xamarin when using this plugin
acuntex commented
Create a custom PushNotificationHandler like this:
public class PushNotificationHandler: DefaultPushNotificationHandler
{
public override void OnBuildNotification(NotificationCompat.Builder notificationBuilder, IDictionary<string, object> parameters)
{
base.OnBuildNotification(notificationBuilder, parameters);
try
{
if (!parameters.TryGetValue("image", out object imageUrlObject))
return;
string imageUrl = imageUrlObject.ToString();
if (string.IsNullOrEmpty(imageUrl))
return;
using (HttpClient httpClient = new HttpClient())
{
byte[] imageBytes = httpClient.GetByteArrayAsync(imageUrl).Result;
Bitmap image = BitmapFactory.DecodeByteArray(imageBytes, 0, imageBytes.Length);
notificationBuilder.SetLargeIcon(Bitmap.CreateBitmap(image));
}
}
catch (Exception)
{
}
}
}
Then where you initialize do:
FirebasePushNotificationManager.Initialize(this, new PushNotificationHandler(), false, true, true);
Just make sure the notification has no "notification" object while sending or the handler won't be called. It only works with data-payload.