【问题标题】:Xamarin.Androdid expandable notificationXamarin.Android 可扩展通知
【发布时间】:2019-10-04 21:21:16
【问题描述】:

我正在关注此链接以创建通知:https://docs.microsoft.com/it-it/xamarin/android/app-fundamentals/notifications/local-notifications

这是我的代码:

Notification.BigTextStyle textStyle = new Notification.BigTextStyle();

            // Fill it with text:
            string longTextMessage = "I went up one pair of stairs.";
            longTextMessage += " / Just like me. ";
            //...
            textStyle.BigText(longTextMessage);

            // Set the summary text:
            textStyle.SetSummaryText("The summary text goes here.");

            // Plug this style into the builder:


            //creo la notifica:
            var builder = new NotificationCompat.Builder(instance, "enter")
                          .SetSmallIcon(global::Android.Resource.Drawable.IcDialogInfo)
                          .SetContentIntent( pending)
                          .SetDefaults((int)NotificationDefaults.Sound)
                          .SetDefaults((int)NotificationDefaults.Vibrate)
                          .SetNumber(count)
                          .SetAutoCancel(true)
                          .SetContentTitle("Proximity") // Set the title
                          .SetContentText($"benvenuto nel beacon di colore {deskOwner},{count}")
                          .SetStyle(textStyle)
                          .Build();
                           count++;
                // Get the notification manager:
                NotificationManager notificationManager = instance.GetSystemService(Context.NotificationService) as NotificationManager;
                // Pubblico la notifica:
                const int notificationId = 0;
                notificationManager.Notify(notificationId, builder);

            return null;
        }

但是在 .SetStyle(textStyle) 给我这个错误: '无法从 'Android.App.Notification.BigTextStyle' 转换为 'Android.Support.V4.App.NotificationCompat.Style' 我该如何解决?

【问题讨论】:

    标签: android xamarin xamarin.android


    【解决方案1】:

    它不起作用的原因是您正在使用 NotificationCompat 但未使用 NotifcationCompat.BigTextStyle 请尝试以下操作:

            NotificationCompat.BigTextStyle textStyle = new NotificationCompat.BigTextStyle();
    
            // Fill it with text:
            string longTextMessage = "I went up one pair of stairs.";
            longTextMessage += " / Just like me. ";
            //...
            textStyle.BigText(longTextMessage);
    
            // Set the summary text:
            textStyle.SetSummaryText("The summary text goes here.");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-03
      • 2017-05-13
      • 2011-06-26
      • 1970-01-01
      • 2012-07-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多