4

It doesn't give any errors or show notifications.

NotificationCompat.Builder builder = new NotificationCompat.Builder(Activity)
            .SetAutoCancel(true)
            .SetContentIntent(resultPendingIntent)
            .SetContentTitle("My Notifications")
            .SetContentText(" Work dammit -_-");
            NotificationManager notificationManager = (NotificationManager)Activity.GetSystemService(Android.Content.Context.NotificationService);
            notificationManager.Notify(ButtonClickNotification, builder.Build());

2 Answers2

1

I found a solution for my problem.

I got my solution from here

void CreateNotification(string title, string desc)
        {
            //Create notification
            var notificationManager = GetSystemService(Context.NotificationService) as 
                 NotificationManager;

            //Create an intent to show ui
            var uiIntent = new Intent(this, typeof(MainActivity));

            //Create the notification
            var notification = new Notification(Resource.Drawable.Icon, title);
            //var notification = new Notification(Android.Resource.Drawable.SymActionEmail,title);

            //Auto cancel will remove the notification once the user touches it
            notification.Flags = NotificationFlags.AutoCancel;

            //Set the notification info
            //we use the pending intent, passing our ui intent over which will get called
            //when the notification is tapped.
            notification.SetLatestEventInfo(this,
                title, desc, PendingIntent.GetActivity(this, 0, uiIntent, 0));

            //Show the notification
            notificationManager.Notify(1, notification);
        }
0

As written in the Documentation, a small icon is required to be set with SetSmallIcon(), before you call builder.Build(). This is most likely your point of issue, since nothing else seems wrong with your code.

Here is an older SO question that may have relevant information in case you run into more trouble with the Notification Builder How exactly to use Notification.Builder

Matthew Andrews
  • 437
  • 1
  • 5
  • 16