Канал уведомлений не найден, когда он уже создан - PullRequest
0 голосов
/ 27 сентября 2019

Я не получаю канал уведомлений об ошибке в Oreo, когда я уже создал его, и он работает, когда приложение находится на переднем плане, это мой код, когда я регистрирую NC на переднем плане, он не нулевой и выдает мне данные, нокогда приложение находится в фоновом режиме, я получаю сообщение об ошибке -

E / NotificationService: Канал не найден для pkg = . . *, channelId =null, id = 0, tag = GCM-уведомление: 141257693, opPkg = . . , callUid = 10530, userId = 0, входящийUserId = 0 ,tificationUid = 10530 ,tification = Notification (channel =null pri = 0 contentView = null vibrate = нулевой звук = нулевые значения по умолчанию = 0x0 flags = 0x10 color = 0x00000000 vis = PRIVATE)

NotificationCompat.Builder notificationBuilder ;
    NotificationManager notificationManager;

    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {

        NotificationChannel nc = notificationManager.getNotificationChannel(getString(R.string.default_notification_channel_id));

        Log.e(TAG, "sendNotification: "+nc );

        notificationManager = getSystemService(NotificationManager.class);

        notificationBuilder = new NotificationCompat.Builder(getApplicationContext(), getString(R.string.default_notification_channel_id));

        notificationBuilder.setChannelId(getString(R.string.default_notification_channel_id));
        if (nc == null) {
            nc = new NotificationChannel(getString(R.string.default_notification_channel_id), getString(R.string.default_notification_channel_name), NotificationManager.IMPORTANCE_HIGH);

            nc.setDescription("Badge Notifications");
            nc.enableLights(true);
            nc.setShowBadge(true);
            nc.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);

            notificationManager.createNotificationChannel(nc);

        }
    } else {
        notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationBuilder = new NotificationCompat.Builder(getApplicationContext());
    }

    notificationBuilder.setSmallIcon(R.drawable.ic_notification)
            .setContentTitle(title)
            .setContentText(messageBody)
            .setAutoCancel(true)
            .setColor(Utils.getPrimaryColor())
            .setStyle(new NotificationCompat.BigTextStyle().bigText(messageBody))
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    notificationManager.notify(0, notificationBuilder.build());

1 Ответ

0 голосов
/ 28 сентября 2019

Я решил проблему, у меня были зависимости fcm от 10.2.1.Говорят, что он включает канал уведомлений, который вам может понадобиться. (Я обновляю его до последней версии 20.0.0, но, поскольку проект устарел, многие функции не были найдены, которые были реализованы в проекте. Поэтому я, наконец, обновил эту версию до 11.4.0 и это сработало. Это была зависимость, в которой есть все методы кода и новейшие функции для одновременной работы канала.

...