使用下面的代码,我的通知仅添加到通知栏,不会显示弹出式消息,就像您在另一个应用程序中收到whatsapp消息一样。是什么让通知发生了这种情况?
private void sendNotification(int distance, ViewObject viewObject) {
Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
notificationIntent.putExtra("path", viewObject.getPath());
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(notificationIntent);
PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(Integer.parseInt(viewObject.getRefId()), PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();
bigText.bigText(String.format(getString(R.string.notification), viewObject.getTitle()));
bigText.setBigContentTitle(getString(R.string.hello));
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setSmallIcon(R.drawable.ic_wald_poi)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_poi))
.setColor(getResources().getColor(R.color.primary))
.setContentTitle(getString(R.string.hello))
.setContentIntent(notificationPendingIntent)
.setContentText(String.format(getString(R.string.notification), viewObject.getTitle()))
.setDefaults(Notification.DEFAULT_ALL)
.setStyle(bigText);
builder.setAutoCancel(true);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, builder.build());
}
发布于 2016-06-26 23:42:41
您必须将通知优先级设置为Notification.PRIORITY_HIGH
或Notification.PRIORITY_MAX
。我还得做.setDefaults(Notification.DEFAULT_ALL)
。
https://stackoverflow.com/questions/29949501
复制相似问题