I am using this to show notifications:
public static void showAlarmNotification(Context context, Class<?> cls, String title, String content, int idNotification){
Intent notificationIntent = new Intent(context, cls);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(cls);
stackBuilder.addNextIntent(notificationIntent);
PendingIntent pendingIntent = stackBuilder.getPendingIntent(idNotification, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID).setPriority(NotificationCompat.PRIORITY_MAX);
Notification notification = builder.setContentTitle(title)
.setContentText(content)
.setAutoCancel(false)
.setOngoing(true)
.setVibrate(new long[] {1000, 1000, 1000})
.setSmallIcon(R.drawable.ic_stat_name)
.setChannelId(NOTIFICATION_CHANNEL_ID)
.setContentIntent(pendingIntent)
.build();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID_ALARM, context.getString(R.string.alarms), NotificationManager.IMPORTANCE_HIGH);
notificationChannel.setSound(null,null);
notificationChannel.setVibrationPattern(new long[] {1000, 1000, 1000});
notificationChannel.enableVibration(true);
notificationManager.createNotificationChannel(notificationChannel);
}
notificationManager.notify(idNotification, notification);
}
It works fine to display a notification. But I want the notification not to disappear automatically as it normally happens, I want it to only go up if the user swipes it up, I have seen applications doing that but I have not found a way to do it
UPDATE
This example shows a notification that is not hidden until the user swipes it up