gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 13:51:40 25 4
gpt4 key购买 nike

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

  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 上运行良好,无需为通知创建任何自定义布局。下部的不同 Action 也能正常工作。重定向到他们的 Activity 后,通知也会被取消。

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

关于android - 无法在android的通知抽屉中展开通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46273692/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com