Локальные уведомления не отображаются в API 27 - PullRequest
0 голосов
/ 15 февраля 2019

Уведомления работают для Api 26 и ниже отлично, но они не работают с API 27.

Вот мой код для создания канала уведомлений:

private void CreateNotificationChannel()
{
    try
    {
        if (Build.VERSION.SdkInt < BuildVersionCodes.O)
        {
            return;
        }

        var notificationManager = (NotificationManager)GetSystemService(NotificationService);
        NotificationChannel mChannel = notifManager.GetNotificationChannel("1");
        if (mChannel == null)
        {
            mChannel = new NotificationChannel("1", "Chat Application", Android.App.NotificationImportance.High);
            mChannel.EnableVibration(true);
            mChannel.SetVibrationPattern(new long[] { 100, 200, 300, 400, 500, 400, 300, 200, 400 });
            notifManager.CreateNotificationChannel(mChannel);
        }
    }
    catch (Exception exception)
    {
        LoggingManager.Error(exception);
    }

}

И мой сервис уведомлений:

var activity = Forms.Context as Activity;

Intent intent = new Intent(activity, typeof(MainActivity));
intent.AddFlags(ActivityFlags.ClearTop);
Random random = new Random();
int pushCount = random.Next(9999 - 1000) + 1000; //for multiplepushnotifications

intent.AddFlags(ActivityFlags.ClearTop);
var pendingIntent = PendingIntent.GetActivity(activity, pushCount, intent, PendingIntentFlags.Immutable);

// Instantiate the builder and set notification elements:
NotificationCompat.Builder builder = new NotificationCompat.Builder(Forms.Context,"1")
                                                           .SetContentTitle(messageTitle)
                                                           .SetDefaults(1|2)
                                                           .SetContentText(Message)
                                                           .SetContentIntent(pendingIntent)
                                                           .SetAutoCancel(true)
                                                           .SetChannelId("1")
                                                           .SetPriority(1);
builder.SetSmallIcon(Resource.Drawable.icon);

// Build the notification:
Notification notification = builder.Build();

// Get the notification manager:
NotificationManager notificationManager = Forms.Context.GetSystemService(Context.NotificationService) as NotificationManager;

// Publish the notification:
notificationManager.Notify(5, notification);

Пожалуйста, помогите мне или дайте мне несколько советов, как я могу решить эту проблему.

Ответы [ 2 ]

0 голосов
/ 15 февраля 2019

У меня такое ощущение, что с созданием вашего канала что-то не так, ниже вы можете проверить мой рабочий фрагмент кода.

 var mChannel = new NotificationChannel(CHANNEL_ID, "Chat Application", Android.App.NotificationImportance.High)
                  {
                      Description = "Firebase Cloud Messages appear in this channel"
                  };
        mChannel.EnableVibration(true);
        mChannel.SetVibrationPattern(new long[] { 100, 200, 300, 400, 500, 400, 300, 200, 400 });           

    var notificationManager = (NotificationManager) GetSystemService(NotificationService);
    notificationManager.CreateNotificationChannel(channel);
0 голосов
/ 15 февраля 2019

Можете ли вы попробовать с уведомлениемManager.Notify (новый Случайный (). Далее (), уведомление);

вместо messagesManager.Notify (5, уведомление);

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...