Java 通知未显示-已设置图标以及小图标、标题和文本

Java 通知未显示-已设置图标以及小图标、标题和文本,java,android,android-intent,push-notification,android-notifications,Java,Android,Android Intent,Push Notification,Android Notifications,我一直在我的另一个应用程序上使用通知,它工作得很好。我还实现了channelId,但当我在新应用程序中使用类似的代码时,通知不会显示出来。未报告任何错误 下面是我正在使用的代码 NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Intent notInten

我一直在我的另一个应用程序上使用通知,它工作得很好。我还实现了
channelId
,但当我在新应用程序中使用类似的代码时,通知不会显示出来。未报告任何错误

下面是我正在使用的代码

NotificationManager mNotificationManager =
                (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

        Intent notIntent = new Intent(context, hk.class);
//        notIntent.setAction(BuildConfig.APP_ID + ".inspire");
        notIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendInt = PendingIntent.getActivity(context, ALARM_REQUEST_CODE,
                notIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        Notification.Builder mBuilder =
                new Notification.Builder(context)
                        .setContentIntent(pendInt)
                        .setSmallIcon(R.drawable.spl)
//                        .setLargeIcon()
                        .setContentTitle(intent.getStringExtra("not_title"))
                        .setContentText(intent.getStringExtra("not_text"))
                        .setPriority(Notification.PRIORITY_HIGH)
                        .setDefaults(Notification.DEFAULT_VIBRATE)
                        .addAction(android.R.drawable.ic_menu_share, "Share", PendingIntent.getActivity(context, 0,
                                new Intent().setAction(Intent.ACTION_SEND).putExtra(Intent.EXTRA_TEXT,
                                         "\n\n" + "-His Holiness Bhakti Rasamrita Swami\n\n").setType("text/plain"), 0))
                        .setWhen(System.currentTimeMillis())
                        .setStyle(new Notification.BigTextStyle().bigText(intent.getStringExtra("big_text")));

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mBuilder.setVisibility(Notification.VISIBILITY_PUBLIC);
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel channel = new NotificationChannel("daily", "Daily Nectar", NotificationManager.IMPORTANCE_HIGH);
            channel.setDescription("Daily Nectar");
            channel.enableLights(true);
            mNotificationManager.createNotificationChannel(channel);
            mBuilder.setChannelId("chId");
        }
        mNotificationManager.notify(ALARM_REQUEST_CODE, mBuilder.build());
        Log.d("AlarmReceiver", "Notification Created"); //this log is printed in console 
我已经使用日志进行了测试,因此我可以确保调用此函数,因此不会出现报警问题

奇怪的是,它也不会抛出任何错误,其他应用程序上非常类似的代码也运行良好。因此,我检查了此应用程序的通知设置,发现通知设置也已启用


无法检测出问题所在。谢谢你的帮助。

出了个愚蠢的错误

注意下面的代码

        NotificationChannel channel = new NotificationChannel("daily", "Daily Nectar", NotificationManager.IMPORTANCE_HIGH);
        channel.setDescription("Daily Nectar");
        channel.enableLights(true);
        mNotificationManager.createNotificationChannel(channel);
        mBuilder.setChannelId("chId");
传递给新NotificationChannel的通道id与在生成器上设置的通道id不同。更新过程中错误引入的错误

快乐编码