无法扩展Android通知抽屉中的通知



在这里,我将消息显示在自定义通知中,但我无法使其可扩展。如果我显示长短信,它将从末端剪切。 到目前为止,我尝试了很多事情:

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

最后,我解决了这个问题,该问题适合Android 7.06.05.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);

最新更新