无法在 android 的通知抽屉中展开通知

Ans*_*agi 5 android push-notification

在这里,我将消息显示到自定义通知中,但我无法使其可展开。如果我显示长文本消息,它会从结尾处被剪掉。到目前为止,我已经尝试了很多事情:

  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());
Run Code Online (Sandbox Code Playgroud)

Ans*_*agi 2

最后我解决了这个问题,该问题对于 来说工作得很好Android 7.06.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);
Run Code Online (Sandbox Code Playgroud)