【问题标题】:status bar notifications xamarin native android状态栏通知 xamarin 本机 android
【发布时间】:2018-05-30 09:01:14
【问题描述】:

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

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());

【问题讨论】:

标签: c# xamarin mobile xamarin.android


【解决方案1】:

我找到了解决问题的方法。

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);
        }

【讨论】:

    【解决方案2】:

    正如Documentation 中所写,在调用builder.Build() 之前,需要设置一个小图标以使用SetSmallIcon()。这很可能是您的问题所在,因为您的代码似乎没有其他问题。

    这是一个较旧的 SO 问题,如果您在使用通知生成器时遇到更多问题How exactly to use Notification.Builder

    ,可能会有相关信息

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-15
      • 2016-02-22
      • 1970-01-01
      相关资源
      最近更新 更多