我是Xamarin的新手,到目前为止这是我的代码.它不会给出任何错误或显示通知.
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());
解决方法
我找到了解决问题的方法.
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,uiIntent,0)); //Show the notification notificationmanager.Notify(1,notification); }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。