我是Xamarin的新手,到目前为止这是我的代码。它不会给出任何错误或显示通知。
''
答案 0 :(得分:1)
我找到了解决问题的方法。
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);
}
答案 1 :(得分:0)
正如Documentation所述,在您致电SetSmallIcon()
之前,需要使用builder.Build()
设置一个小图标 。这很可能是您的问题所在,因为您的代码似乎没有其他任何问题。
以下是较旧的SO问题,如果您在使用Notification Builder How exactly to use Notification.Builder
时遇到更多麻烦,可能会提供相关信息