简体   繁体   中英

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. Hope it help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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