Android Heads Up通知未显示

时间:2017-12-13 14:42:29

标签: java android notifications

我无法找到构建通知的错误。

我希望通知在手机处于活动状态时显示在顶部 在手机处于睡眠状态时锁定屏幕上。

这是我尝试过的代码。但是无法实现结果。

PendingIntent pendingIntent = PendingIntent.getActivity(context,0, openIntent,PendingIntent.FLAG_UPDATE_CURRENT);

NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "Normal")
    .setSmallIcon(R.drawable.ic_folder)
    .setContentIntent(pendingIntent)
    .setPriority(NotificationCompat.PRIORITY_MAX)
    .setCategory(NotificationCompat.CATEGORY_MESSAGE)
    .setVibrate(new long[] {1000})
    .setContentTitle(mainListItem.getTitle())
    .setContentText(mainListItem.getDetail())
    .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
    .setAutoCancel(true)
    .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);


NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

notificationManager.notify(0,builder.build());

1 个答案:

答案 0 :(得分:0)

现在回答很晚......

好像你的代码对我来说工作正常,但由于某些原因,这会阻止你的抬头通知出现。

  1. 请检查您当前正在使用的应用程序是否由某些系统设置管理,例如您的手机设置的通知中心,如果这已禁用您的抬头通知,那么您的抬头通知无法显示在我的手机中,Notification Center将我的应用程序的通知设置为未选中或禁用“横幅”(显示在状态栏顶部)设置,默认情况下我在手机中安装了任何应用程序。然后我的抬头通知没有显示。 您需要选中或启用

  2. 如果您的应用在Android 26及更高版本中运行,则需要创建通知渠道,请检查您的通知设置,确保不会阻止您的应用通知。 希望它有所帮助。