尝试使用通知 inboxStyle 在通知中显示更多类似于 GMAIL 应用程序的行,但它不起作用
Trying to use notification inboxStyle to show more lines similar to GMAIL app in notification but it doesn't work
这是我的代码:
NotificationManager notifManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
Notification.InboxStyle inboxStyle = new Notification.InboxStyle();
inboxStyle.setBigContentTitle("Title - Notification");
inboxStyle.setSummaryText("TEST");
inboxStyle.addLine("LINE");
Notification noti = new Notification.Builder(getActivity())
.setContentTitle("PSNGR")
.setContentText("PITSTOP BLA").setSmallIcon(R.drawable.notification_icon)
.setStyle(inboxStyle)
.setContentIntent(null).build();
noti.flags |= Notification.FLAG_AUTO_CANCEL;
notifManager.notify(0, noti);
但是 InboxStyle 通知没有任何效果。我只得到 PSNGR 和 PITSTOP BLA,这是为什么?
PS:也尝试使用 BitTextStyle() 但也没有看到任何内容:
对于此代码:
NotificationManager notifManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getActivity())
.setContentTitle("PSNGR")
.setSmallIcon(R.drawable.ic_launcher)
.setStyle(new NotificationCompat.BigTextStyle().bigText("MATA"))
.setStyle(new NotificationCompat.BigTextStyle().bigText("MATA2"))
.setAutoCancel(true)
.setContentIntent(null);
notifManager.notify(0, notificationBuilder.build());
我只看到:"PSNGR"
我使用 RemoteViews 而不是普通通知:
NotificationManager notifManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(getActivity()).setSmallIcon(R.drawable.ic_launcher);
RemoteViews mContentView = new RemoteViews(getActivity().getPackageName(), R.layout.pitstop_notification);
mContentView.setImageViewResource(R.id.image, R.drawable.notification_icon);
mContentView.setTextViewText(R.id.title, "Custom notification");
mContentView.setTextViewText(R.id.text, "This is a custom layout");
mContentView.setTextViewText(R.id.text2, "This is a custom layout2");
mBuilder.setContent(mContentView);
notifManager.notify(0, mBuilder.build());
这是我的代码:
NotificationManager notifManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
Notification.InboxStyle inboxStyle = new Notification.InboxStyle();
inboxStyle.setBigContentTitle("Title - Notification");
inboxStyle.setSummaryText("TEST");
inboxStyle.addLine("LINE");
Notification noti = new Notification.Builder(getActivity())
.setContentTitle("PSNGR")
.setContentText("PITSTOP BLA").setSmallIcon(R.drawable.notification_icon)
.setStyle(inboxStyle)
.setContentIntent(null).build();
noti.flags |= Notification.FLAG_AUTO_CANCEL;
notifManager.notify(0, noti);
但是 InboxStyle 通知没有任何效果。我只得到 PSNGR 和 PITSTOP BLA,这是为什么?
PS:也尝试使用 BitTextStyle() 但也没有看到任何内容: 对于此代码:
NotificationManager notifManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getActivity())
.setContentTitle("PSNGR")
.setSmallIcon(R.drawable.ic_launcher)
.setStyle(new NotificationCompat.BigTextStyle().bigText("MATA"))
.setStyle(new NotificationCompat.BigTextStyle().bigText("MATA2"))
.setAutoCancel(true)
.setContentIntent(null);
notifManager.notify(0, notificationBuilder.build());
我只看到:"PSNGR"
我使用 RemoteViews 而不是普通通知:
NotificationManager notifManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(getActivity()).setSmallIcon(R.drawable.ic_launcher);
RemoteViews mContentView = new RemoteViews(getActivity().getPackageName(), R.layout.pitstop_notification);
mContentView.setImageViewResource(R.id.image, R.drawable.notification_icon);
mContentView.setTextViewText(R.id.title, "Custom notification");
mContentView.setTextViewText(R.id.text, "This is a custom layout");
mContentView.setTextViewText(R.id.text2, "This is a custom layout2");
mBuilder.setContent(mContentView);
notifManager.notify(0, mBuilder.build());