簡體   English   中英

Android推送通知消息未顯示

[英]Android push notification message not being displayed

我正在使用推送通知,但是在理解最近發現的錯誤時遇到了麻煩。

我在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());

感謝@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);

現在每台設備都可以正常使用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM