0

i'm trying to show Notification content as popup on android 5.0 and above, but my coding this feature show only small icon on android status bar and i have to pull down status bar layout to show received notification's content

public static void createNotification(Context context, Class activity, String title, String subject) {
    Intent intent = new Intent(context, activity);
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, Intent.FLAG_ACTIVITY_CLEAR_TOP);
    Bitmap icon = BitmapFactory.decodeResource(context.getResources(),
            R.drawable.dollar);
    Notification notify = new NotificationCompat.Builder(context)
            .setAutoCancel(true)
            .setContentTitle(title)
            .setContentText(subject)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setLargeIcon(icon)
            .setPriority(0)
            .setLights(Color.BLUE, 500, 500)
            .setContentIntent(pendingIntent)
            .build();

    notify.flags |= Notification.FLAG_AUTO_CANCEL;
    NOTIFICATIONMANAGER = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
    NOTIFICATIONMANAGER.notify(159753456, notify);
}
tux-world
  • 2,680
  • 6
  • 24
  • 55

1 Answers1

2

You need to set the priority to high or max in order to trigger a heads-up notification on Android versions that support it:

Notification notify = new NotificationCompat.Builder(context)
    // ...
    .setPriority(NotificationCompat.PRIORITY_HIGH)
    .setDefaults(NotificationCompat.DEFAULT_VIBRATE)
    .build();

As stated in the official Notification documentation the notification also needs either a vibration or a ringtone to produce a heads-up notification:

The notification has high priority and uses ringtones or vibrations

Also see this question for more information on heads-up notifications.

Community
  • 1
  • 1
TR4Android
  • 3,200
  • 16
  • 21