Java 防止通知自动隐藏

Java 防止通知自动隐藏,java,android,Java,Android,我正在使用它显示通知: public static void showAlarmNotification(Context context, Class<?> cls, String title, String content, int idNotification){ Intent notificationIntent = new Intent(context, cls); notificationIntent.setFlags(Intent.FLAG_ACTIVIT

我正在使用它显示通知:

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);
}
publicstaticvoidshowAlarmNotification(上下文上下文、类cls、字符串标题、字符串内容、int-idNotification){
意向通知意向=新意向(上下文,cls);
notificationIntent.setFlags(Intent.FLAG\u ACTIVITY\u CLEAR\u TOP);
TaskStackBuilder stackBuilder=TaskStackBuilder.create(上下文);
stackBuilder.addParentStack(cls);
stackBuilder.addNextIntent(通知意图);
PendingEvent PendingEvent=stackBuilder.GetPendingEvent(idNotification,PendingEvent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder=新建NotificationCompat.Builder(上下文、通知\u通道\u ID)。设置优先级(NotificationCompat.PRIORITY\u MAX);
通知通知=builder.setContentTitle(标题)
.setContentText(内容)
.setAutoCancel(错误)
.正在进行(正确)
.setVibrate(新长[]{1000,1000,1000})
.setSmallIcon(R.drawable.ic_stat_name)
.setChannelId(通知通道ID)
.setContentIntent(挂起内容)
.build();
NotificationManager NotificationManager=(NotificationManager)context.getSystemService(context.NOTIFICATION\u服务);
if(Build.VERSION.SDK\u INT>=Build.VERSION\u code.O){
NotificationChannel NotificationChannel=新建NotificationChannel(通知通道ID报警,context.getString(R.string.alarms),NotificationManager.IMPORTANCE高);
notificationChannel.setSound(null,null);
notificationChannel.setVibrationPattern(新的长[]{1000,1000,1000});
通知通道。启用振动(真);
notificationManager.createNotificationChannel(notificationChannel);
}
notificationManager.notify(idNotification,notification);
}
显示通知效果良好。但我希望通知不会像正常情况下那样自动消失,我希望只有当用户刷起时通知才会自动消失,我见过应用程序这样做,但我没有找到一种方法

更新

此示例显示了一个通知,该通知在用户刷起之前不会隐藏


这似乎是一个带有设置类别的通知


另请参见分类

解决方案是将
setContentIntent
更改为
setFullScreenIntent

哪些应用程序必须看到这样做?OSI可以处理多长时间的通知刚刚上传了一段视频,显示我需要什么是可能的,我更新了我尝试过的问题,但没有成功