Android推送通知消息未显示

时间:2015-02-25 14:20:19

标签: android notifications google-cloud-messaging

我正在处理推送通知,而我很难理解我最近发现的错误。

我在Galaxy S4 Mini,Nexus 4,Galaxy Note 2,MOTO E和MOTO G上收到推送信息。

但是在Galaxy S5上,我收到推送通知,我可以看到状态栏上的消息,但是当我拉下屏幕时,消息不存在。 我看到了我的形象,但我没有看到这条消息。

有没有人对这个问题有所了解?

代码:

NotificationCompat.Builder nBuilder;
nBuilder = new NotificationCompat.Builder(context)
    .setSmallIcon(smallIcon)
    .setAutoCancel(true).setTicker(message)
    .setVibrate(new long[] { 100, 250, 100, 250, 100, 250 })
    .setSound(alarmSound)
    .setPriority(Notification.PRIORITY_MAX);

NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
inboxStyle.setBigContentTitle(appName);
for (String notification : notifications) {  
    inboxStyle.addLine(notification);  
}  
nBuilder.setStyle(inboxStyle); 

nBuilder.setContentIntent(resultPendingIntent);
nBuilder.setDeleteIntent(deletePendingIntent);

mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, nBuilder.build());

1 个答案:

答案 0 :(得分:7)

感谢@Eran(https://stackoverflow.com/a/25608914/3050951)和@MartinCR(https://stackoverflow.com/a/25608962/3050951),我能够解决问题。

Nexus 4(带棒棒糖)和Galaxy S5的推送通知消息为空白。所以在我的代码中我改变了:

NotificationCompat.Builder nBuilder;
nBuilder = new NotificationCompat.Builder(context)
    .setSmallIcon(smallIcon)
    .setAutoCancel(true).setTicker(message)
    .setVibrate(new long[] { 100, 250, 100, 250, 100, 250 })
    .setSound(alarmSound)
    .setPriority(Notification.PRIORITY_MAX);

要:

NotificationCompat.Builder nBuilder;
nBuilder = new NotificationCompat.Builder(context)
    .setDefaults(Notification.DEFAULT_ALL)
    .setSmallIcon(smallIcon)
    .setWhen(System.currentTimeMillis())
    .setAutoCancel(true)
    .setContentTitle(appName)  // <--- add this
    .setContentText(message)   // <--- and this
    .setTicker(message)
    .setVibrate(new long[] { 100, 250, 100, 250, 100, 250 })
    .setSound(alarmSound)
    .setPriority(Notification.PRIORITY_MAX);

现在每台设备都可以正常使用。

相关问题