繁体   English   中英

使用多个通知第二个通知显示在崩溃模式Android

[英]With multiple notifications second notification showing in collapse mode Android

我在我的Android应用程序中显示多个通知。

当有单一通知时,它正确显示。

在此输入图像描述

但是当我生成第二个通知时,默认情况下显示崩溃的第二个通知。

在此输入图像描述

如果我手动展开第二个通知,它显示为:

在此输入图像描述

我想默认以扩展模式显示通知。

这是我的代码:

int num = (int) System.currentTimeMillis();

        PendingIntent pendingIntent = PendingIntent.getActivity(this, num  /* Request code */, intent,
                PendingIntent.FLAG_ONE_SHOT);


        NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
        bigTextStyle.setBigContentTitle(title);
        bigTextStyle.bigText(messageBody);

        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.corco)
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setStyle(bigTextStyle)
                .setContentIntent(pendingIntent);

        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(num  /* ID of notification */, notificationBuilder.build());

我错过了什么吗? 或做错了什么?

提前致谢。

我解决了 我没有为崩溃通知设置任何ContentTitle和ContentText。

这是我更新的代码:

int num = (int) System.currentTimeMillis();

        PendingIntent pendingIntent = PendingIntent.getActivity(this, num  /* Request code */, intent,
                PendingIntent.FLAG_ONE_SHOT);


        NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
        bigTextStyle.setBigContentTitle(title);
        bigTextStyle.bigText(messageBody);

        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.corco)
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setStyle(bigTextStyle)
                .setContentTitle(title)
                .setContentText(messageBody)
                .setContentIntent(pendingIntent);

        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(num  /* ID of notification */, notificationBuilder.build());

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM