0

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

Example (YouTube)

JP711
  • 533
  • 6
  • 15
  • 1
    What applications have to seen do this? How long notifications are shown are handled by the OS – tyczj Apr 20 '21 at 20:46
  • I just uploaded a video showing what I need is possible, I updated the question – JP711 Apr 20 '21 at 21:03

2 Answers2

0

That appears to be a notification with a set category of CATEGORY_ALARM.

See also system-wide category

tyczj
  • 71,600
  • 54
  • 194
  • 296
0

The solution is to change setContentIntent to setFullScreenIntent, this is the source

JP711
  • 533
  • 6
  • 15