简体   繁体   English

Android Heads Up通知未显示

[英]Android Heads Up notification not showing up

I am not able to find where i am getting wrong in building the Notification. 我找不到在构建通知时出错的地方。

I want the notification to show at top when phone is active and on lock screen when phone is in sleep. 我希望通知在手机处于活动状态时显示在顶部,而在手机处于睡眠状态时显示在锁定屏幕上。

Here is the code that i have tried. 这是我尝试过的代码。 But not able to achive the result. 但是无法达到结果。

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

It's to late to answer... 答案迟到了...

Seems like your code is work fine for me, but for some reasons, that stop your heads-up notification to showing up. 似乎您的代码对我来说很好用,但是由于某些原因,这使您的提示通知无法显示。

  1. Please check if your current working app that's managed by some system settings like Notification Center of your phone settings, if that's disabled your heads up notification, then your heads up notification not able to show as the same in my phone the Notification Center set my app's notifications to Unchecked or Disabled the "Banners" (Display on the top of status bar) setting, it does by default when i installed any applications in my phone. 请检查您当前正在运行的应用是否由某些系统设置(例如手机设置的通知中心)管理,如果禁用了抬头通知,则抬头通知无法在手机中显示为相同状态,通知中心将我的应用设置为通知“未选中”或“禁用”“横幅”(状态栏顶部显示)设置,默认情况下,当我在手机中安装了任何应用程序时。 then my heads up notification is not showing. 那么我的抬头通知就不会显示。 You need to checked or enabled it . 您需要选中或启用它

  2. If your app run in the android version 26 and later, you need to create a notification channel and please check your Notification Settings make sure that's not block your app's notifications. 如果您的应用程序在android 26及更高版本中运行,则需要创建一个通知频道,请检查“通知设置”以确保它不会阻止应用程序的通知。 Hope it help. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM