锁屏通知文本
问题描述:
我是建设和轻松的Android应用程序。 我遇到了通知问题。当应用程序收到通知时,它会正确地显示所有图片和文本,而在锁定屏幕上,如果手机已锁定,则不会显示文本。要查看文本,我必须向下滑动通知。锁屏通知文本
这是代码:
NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();
bigText.bigText(body);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_stat_luceterna_notifica_90)
.setContentTitle("Luceterna")
.setLargeIcon((((BitmapDrawable) this.getResources().getDrawable(R.mipmap.ic_launcher_lux)).getBitmap()))
.setAutoCancel(true)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
mBuilder.setStyle(bigText);
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
mBuilder.setSound(alarmSound);
NotificationManager mNotificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
可以请人帮助我吗?我找不到任何问题的答案。
在此先感谢。
答
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher) // notification icon
.setContentTitle("Notification!") // title for notification
.setContentText("Hello word") // message for notification
.setAutoCancel(true); // clear notification after click
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pi = PendingIntent.getActivity(this,0,intent,Intent.FLAG_ACTIVITY_NEW_TASK);
mBuilder.setContentIntent(pi);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());
一个例子来帮助你
答
我知道它已经有一段时间,因为你问到这个问题,但我今天遇到了同样的问题,找到了sollution。
为了解决这个问题,你必须覆盖NotificationCompatsetContentTitle
和 setContentDescritption
随着BigTextStyle的:setBigContentTitle
和bigText
你必须使用他们两个,里面同样的文本。所以,你的代码看起来像:
String title = "Title";
String description = "Description;
NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
bigTextStyle.setBigContentTitle(title);
bigTextStyle.bigText(description);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setContentTitle(title)
.setContentText(description)
.setSmallIcon(R.drawable.ic_launcher)
.setStyle(bigTextStyle);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());
对不起,我忘了最后的代码行:mNotificationManager.notify(MESSAGE_NOTIFICATION_ID,mBuilder.build()); –