已创建时未找到通知渠道

问题描述 投票:0回答:1

我已经创建了Oreo,并且在app处于前台时可以在错误中找到通知通道,这是我的代码,当我在前台登录NC时,它不是null并提供了数据,但是该应用程序在后台出现错误-

E / NotificationService:找不到pkg = 的频道。。*,channelId = null,id = 0,标记= GCM-Notification:141257693,opPkg = 。] >。,callingUid = 10530,userId = 0,incomingUserId = 0,notificationUid = 10530,notification = Notification(channel = null pri = 0 contentView = null振动= null声音= null默认值= 0x0标志= 0x10颜色= 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());

我已经创建了Oreo并在应用程序处于前台状态时在错误中找不到错误的通知通道,这是我的代码,当我在前台登录NC时不为空...

android firebase push-notification android-notifications android-8.0-oreo
1个回答
0
投票

我解决了这个问题,我的fcm依赖项是10.2.1。据说包括通知通道,您必须使用它。(我将其更新为最新的20.0.0,但由于该项目较旧,因此未找到该项目中已实现的许多功能。因此,我最终升级了11.4 .0,并且有效。这是具有所有代码方法和最新功能的依赖关系,以使通道同时工作。

© www.soinside.com 2019 - 2024. All rights reserved.