Java android中未显示的通知

Java android中未显示的通知,java,android,notifications,Java,Android,Notifications,我有多个通知,但是,如果时间到了,其他通知不会出现,你知道我该如何解决这个问题吗?每个通知都有唯一的数据尝试了这个通知,但不起作用 O 通知出版商 public void onReceive(Context context, Intent intent) { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVI

我有多个通知,但是,如果时间到了,其他通知不会出现,你知道我该如何解决这个问题吗?每个通知都有唯一的数据尝试了这个通知,但不起作用

O 通知出版商

 public void onReceive(Context context, Intent intent) {
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = intent.getParcelableExtra(NOTIFICATION);
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        int importance = NotificationManager.IMPORTANCE_HIGH;
        NotificationChannel notificationChannel = new NotificationChannel(SchedulerFragment.NOTIFICATION_CHANNEL_ID, "NOTIFICATION_CHANNEL_NAME", importance);
        assert notificationManager != null;
        notificationManager.createNotificationChannel(notificationChannel);
    }
    int id = intent.getIntExtra(NOTIFICATION_ID, 0);
    String con = intent.getStringExtra(NOTIF_CONTENT);
    assert notificationManager != null;
    notificationManager.notify(id, notification);

您可以尝试以下代码,此方法用于生成通知。如果不同的通知具有不同的
通道ID
,则可以同时生成多个通知

    private void initNotification(Context context,String channelId,String channelName,String title,String content){
        Intent activityIntent = new Intent(context,MainActivity.class);
        PendingIntent pi = PendingIntent.getActivity(context,0,activityIntent,PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationChannel channel = new NotificationChannel(channelId,
                channelName, NotificationManager.IMPORTANCE_DEFAULT);
        NotificationManager manager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
        manager.createNotificationChannel(channel);
        Notification notification = new NotificationCompat.Builder(context,channelId)
                .setContentTitle(title)
                .setContentText(content)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setWhen(System.currentTimeMillis())
                .setContentIntent(pi)
                .build();
        manager.notify(Integer.parseInt(channelId),notification);
    }
确保
字符串channelID
的值不同,以生成多个通知


用户将添加提醒(通知)以添加随机频道id,并且NotificationManager位于BroadcastReceiver中。只有当频道id不同时,才能同时显示每个频道的通知。
    private void initNotification(Context context,String channelId,String channelName,String title,String content){
        Intent activityIntent = new Intent(context,MainActivity.class);
        PendingIntent pi = PendingIntent.getActivity(context,0,activityIntent,PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationChannel channel = new NotificationChannel(channelId,
                channelName, NotificationManager.IMPORTANCE_DEFAULT);
        NotificationManager manager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
        manager.createNotificationChannel(channel);
        Notification notification = new NotificationCompat.Builder(context,channelId)
                .setContentTitle(title)
                .setContentText(content)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setWhen(System.currentTimeMillis())
                .setContentIntent(pi)
                .build();
        manager.notify(Integer.parseInt(channelId),notification);
    }