安卓手机通知抽屉中无法展开通知

5

在这里,我将消息显示到自定义通知中,但我无法使其可扩展。如果我显示长文本消息,它会从末尾被截断。 目前为止,我已经尝试了很多方法,例如:

  Bitmap icon = BitmapFactory.decodeResource(this.getResources(), R.mipmap.ic_launcher);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        mBuilder.setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle("New message from " + chatContacts.getName())
                .setContentText("")
                .setLargeIcon(icon)
                .setAutoCancel(true)
                .setWhen(System.currentTimeMillis())
                .setStyle(new NotificationCompat.InboxStyle()
                        .setBigContentTitle("" + message)
                        .setSummaryText("New message from " + chatContacts.getName()))
                .setContentIntent(contentIntent);
    } else if (Build.VERSION_CODES.M >= Build.VERSION_CODES.KITKAT) {
        NotificationCompat.InboxStyle inboxStyle =
                new NotificationCompat.InboxStyle();
        String[] events = new String[6];
        inboxStyle.setBigContentTitle("Event tracker details:");
        inboxStyle.addLine(message);
        mBuilder.setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle(chatContacts.getName())
                .setAutoCancel(true)
                .setStyle(inboxStyle)
                .setWhen(System.currentTimeMillis())
                .setContentIntent(contentIntent);
    } else {
        mBuilder.setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle(getString(R.string.app_name))
                .setCustomBigContentView(contentView)
                .setWhen(System.currentTimeMillis()).setAutoCancel(true)
                .setContentIntent(contentIntent);
    }
    NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();
    bigText.bigText(message);
    mBuilder.setStyle(bigText);
    nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(0, mBuilder.build());

请添加通知快照 - nomag
1个回答

2
最后,我解决了这个问题,在不创建任何自定义通知布局的情况下,它可以在Android 7.0、6.0和5.0上正常工作。较低部分的不同操作也正常工作。通知在重定向到它们的活动后也会被取消。
// Create the reply action and add the remote input.
        Notification.Action actionLead =
                new Notification.Action.Builder(0,
                        "Lead Info", contentLeadInfoIntent)
                        .build();
        Notification.Action actionRecordFollowUp =
                new Notification.Action.Builder(0,
                        "Record Follow up", contentRecordFollowupIntent)
                        .build();

        // Build the notification and add the action.
        Notification newMessageNotification =
                new Notification.Builder(this)
                        .setSmallIcon(R.mipmap.ic_launcher)
                        .setContentTitle("Follow Up Alert")
                        .setContentText(contentText)
                        .setStyle(new Notification.BigTextStyle().bigText(contentText))
                        .addAction(actionLead)
                        .addAction(actionRecordFollowUp)
                        .setDefaults(NotificationCompat.DEFAULT_SOUND)
                        .setContentIntent(contentRecordFollowupIntent)
                        .setColor(getResources().getColor(R.color.colorPrimary))
                        .build();

        // Issue the notification.
        notificationManager.notify(NOTIFICATION_ID, newMessageNotification);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接