【发布时间】:2017-07-21 10:00:37
【问题描述】:
我尝试使用NotificationCompat 推送通知:
NotificationCompat.Builder b = new NotificationCompat.Builder(this);
b.setAutoCancel(true)
.setDefaults(NotificationCompat.DEFAULT_ALL)
.setWhen(System.currentTimeMillis())
.setSmallIcon(this.getResources().
getIdentifier("ic_launcher", "mipmap", this.getPackageName()))
.setLargeIcon(BitmapFactory.decodeResource(this.getResources(),
this.getResources().
getIdentifier("ic_launcher", "mipmap", this.getPackageName())))
.setTicker("God Reacts")
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setPriority(Notification.PRIORITY_MAX)
.setContentTitle(data.get("lineOne"))
.setContentText(data.get("lineTwo"))
.setContentInfo("Spread the message !");
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this,getMainActivityClass()),
PendingIntent.FLAG_UPDATE_CURRENT);
b.setContentIntent(contentIntent);
NotificationManager nm = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(1, b.build());
但在少数设备(三星、MI 等)中未显示通知横幅。 通知会随着声音和振动在操作托盘中滑动。
但在少数设备中,当应用程序关闭/后台/前台时,它会完美显示。它正确弹出的设备使用棉花糖。是由于特定的操作系统吗?还是与设备相关的问题?我需要补充什么?
【问题讨论】:
-
只是一些特殊情况,一些设备可能会安装通知清理应用程序,他们可以清理你的通知。我以前遇到过这个问题,它完全让我发疯。也许你可以检查一下。
-
@Spark.Bao 我不这么认为。我在没有通知清理应用程序的情况下在 2 个真实设备上检查过。我不明白这些问题发生的原因
-
@josealfonsomora 是的,我做到了。