c# – 状态栏通知xamarin native android
发布时间:2020-12-15 22:51:36 所属栏目:百科 来源:网络整理
导读:我是Xamarin的新手,到目前为止这是我的代码.它不会给出任何错误或显示通知. NotificationCompat.Builder builder = new NotificationCompat.Builder(Activity) .SetAutoCancel(true) .SetContentIntent(resultPendingIntent) .SetContentTitle("My Notificat
我是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()); 解决方法
我找到了解决问题的方法.
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,uiIntent,0)); //Show the notification notificationManager.Notify(1,notification); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |