Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Push notification #151

Open
Monikaprime opened this issue Jul 20, 2020 · 1 comment
Open

Custom Push notification #151

Monikaprime opened this issue Jul 20, 2020 · 1 comment

Comments

@Monikaprime
Copy link

how can I have custom notification builder in xamarin when using this plugin

@acuntex
Copy link

acuntex commented Sep 4, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants