C# xamarin原生android的状态栏通知

C# xamarin原生android的状态栏通知,c#,xamarin,mobile,xamarin.android,C#,Xamarin,Mobile,Xamarin.android,它不会给出任何错误或显示通知 NotificationCompat.Builder builder = new NotificationCompat.Builder(Activity) .SetAutoCancel(true) .SetContentIntent(resultPendingIntent) .SetContentTitle("My Notifications") .SetContentT

它不会给出任何错误或显示通知

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());
如中所述,在调用
builder.Build()
之前,需要使用
SetSmallIcon()
设置一个小图标。这很可能是您的问题所在,因为您的代码似乎没有其他问题


这是一个较老的SO问题,可能有相关信息,以防您在使用Notification Builder时遇到更多问题。

我找到了解决问题的方法


选中此处设置通知功能
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);
        }