在崩溃模式Android

时间:2017-06-19 09:56:13

标签: android notifications

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

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

enter image description here

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

enter image description here

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

enter image description here

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

这是我的代码:

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());

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

提前致谢。

1 个答案:

答案 0 :(得分:0)

我解决了。我没有为崩溃通知设置任何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());