安卓通知内容文字无法在4.4.4 Kitkat系统中显示,但可以在5.0 Lollipop系统中显示。

5

我为我的应用程序实现了Android通知,用于解析推送通知。但最近我发现通知内容在KitKat系统上无法显示,只有在Lollipop系统上才能显示。

以下是图片...
在KitKat 4.4.4上:
on kitkat 4.4.4

在Lollipop 5.0上:
enter image description here

两张图片的代码是相同的:

NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext);


Notification notification = mBuilder.setSmallIcon(smallIcon).setTicker(title) //title
        .setWhen(System.currentTimeMillis())
        .setAutoCancel(true)
        .setContentTitle(title)
        .setStyle(inboxStyle)
        .setContentIntent(resultPendingIntent)
        .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
        .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), icon))
        .setContentText(notifMessage)
        .build();

NotificationManager notificationManager = (NotificationManager) mContext
    .getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(mNotificationId, notification);

提供信息,我使用的是构建工具23.0.2(在撰写本问题时最新)。以下是我的应用程序build.gradle文件:

apply plugin: 'com.android.application'

android {
         compileSdkVersion 23
         buildToolsVersion "23.0.2"
...

这个差异是怎么回事呢?非常感谢您的帮助。

1个回答

3
解决方法:只需替换此部分即可。
.setWhen(System.currentTimeMillis())

使用以下代码:
.setWhen(0)

我不知道也不在意为什么会发生这种情况。我认为这是一个错误。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接