Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

How to handle NotificationCompat.Builder setTimeoutAfter

$
0
0

Is there a way to handle (maybe a method override) when a push notification has timed out after setting the setTimeoutAfter? I'm wanting to execute an API after the timeout period has passed.

Here is what my SendLocalNotification method looks like in my FirebaseService class. This is where I'm setting my notification timeout:

void SendLocalNotification(string body)
        {
            //Unique request code to avoid PendingIntent collision.
            var requestCode = new Random().Next();

            // accept intent
            var acceptIntent = new Intent(this, typeof(MainActivity));
            acceptIntent.SetAction("ACCEPT_ACTION");
            var pendingIntentAccept = PendingIntent.GetActivity(this, requestCode, acceptIntent, PendingIntentFlags.OneShot);

            // decline intent
            var declineIntent = new Intent(this, typeof(MainActivity));
            declineIntent.SetAction("DECLINE_ACTION");
            var pendingIntentDecline = PendingIntent.GetActivity(this, requestCode, declineIntent, PendingIntentFlags.OneShot);

            var intent = new Intent(this, typeof(MainActivity));
            intent.AddFlags(ActivityFlags.SingleTop);

            var notificationBuilder = new NotificationCompat.Builder(this)
                .AddAction(0, "Accept", pendingIntentAccept)
                .AddAction(0, "Decline", pendingIntentDecline)

                .SetContentTitle("Content Title")
                .SetSmallIcon(Resource.Drawable.laundry_basket_icon_15875)
                .SetContentText("content text")
                .SetContentInfo("content info") // i think content info and sub-text overwrite each other
                .SetSubText("sub text")
                .SetTimeoutAfter(60000)
                .SetAutoCancel(true)
                .SetShowWhen(true)
                .SetContentIntent(pendingIntentAccept)
                .SetContentIntent(pendingIntentDecline);

            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                notificationBuilder.SetChannelId(AppConstants.NotificationChannelName);
            }

            var notificationManager = NotificationManager.FromContext(this);
            notificationManager.Notify(0, notificationBuilder.Build());
        }

Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>