Уведомление многострочное
Как сделать длинное уведомление многострочным. Я использую приведенный ниже фрагмент кода, но его не работает:
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setContentTitle(title)
.setSmallIcon(R.drawable.icon)
.setStyle(new NotificationCompat.BigTextStyle().bigText(message))
.setContentText(message)
.setContentIntent(pIntent);
return mBuilder.build();
Ответы
Ответ 1
Добавьте это:
NotificationCompat.Builder builder = new NotificationCompat.Builder(
context);
Notification notification = builder.setContentIntent(contentIntent)
.setSmallIcon(icon).setTicker(appname).setWhen(0)
.setAutoCancel(true).setContentTitle(appname)
.setStyle(new NotificationCompat.BigTextStyle().bigText(message))
.setContentText(message).build();
notificationManager.notify(0, notification);
Также проверьте: Многострочное уведомление
Ответ 2
Bitmap icon1 = BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setSmallIcon(getNotificationIcon()).setLargeIcon(icon1)
.setTicker(title)
.setContentTitle(title)
.setContentText(message)
.setAutoCancel(true)
.setTicker(message)
.setStyle(new NotificationCompat.BigTextStyle().bigText(title))
.setStyle(new NotificationCompat.BigTextStyle().bigText(message))
.setPriority(Notification.PRIORITY_MAX)
.setContentIntent(pIntent)
.setContent(remoteViews)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setVibrate(new long[] {1, 1, 1})
.setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_launcher))
.setDefaults(Notification.DEFAULT_SOUND)
.setDefaults(Notification.DEFAULT_ALL);
NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notify = new Notification();
notify.flags = Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_ONLY_ALERT_ONCE;
Random random = new Random();
notificationmanager.notify(random.nextInt(), builder.build());
Ответ 3
Notification notification = new Notification.Builder(context)
.setContentTitle(title)
.setSmallIcon(icon)
.setStyle(new Notification.BigTextStyle().bigText(notificationMessage))
.setAutoCancel(true)
.setContentIntent(intent)
.build();
Ответ 4
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(getNotificationIcon())
.setContentTitle(Html.fromHtml(title))
.setContentText(Html.fromHtml(messageBody))
.setAutoCancel(true)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(messageBody))
.setSound(defaultSoundUri)
.setDefaults(Notification.DEFAULT_ALL)
.setPriority(Notification.PRIORITY_HIGH)
.setContentIntent(pendingIntent)
.setColor(whiteIcon ? getResources().getColor(R.color.colorPrimary) : getResources().getColor(android.R.color.transparent));