Android持续通知-仅自动折叠/隐藏/最小化到状态栏(不取消)

Android持续通知-仅自动折叠/隐藏/最小化到状态栏(不取消),android,notifications,Android,Notifications,我正在建立一个持续的通知。当触发通知时,它将显示在显示屏顶部,直到用户滑动它,然后通知仅显示在状态栏中 如何设置计时器,使通知自动折叠为仅在状态栏中?e、 g.所以用户不需要刷卡就可以将其从主显示器上移除?不是取消-只是最小化到状态栏 下面的代码包含正在进行的通知及其属性,以及2个操作:单击正文打开应用程序,单击按钮关闭通知 Intent innerIntent = new Intent(context, MainActivity.class); PendingIntent notificati

我正在建立一个持续的通知。当触发通知时,它将显示在显示屏顶部,直到用户滑动它,然后通知仅显示在状态栏中

如何设置计时器,使通知自动折叠为仅在状态栏中?e、 g.所以用户不需要刷卡就可以将其从主显示器上移除?不是取消-只是最小化到状态栏

下面的代码包含正在进行的通知及其属性,以及2个操作:单击正文打开应用程序,单击按钮关闭通知

Intent innerIntent = new Intent(context, MainActivity.class);
PendingIntent notificationPendingIntent = PendingIntent.getActivity(context, 0, innerIntent, PendingIntent.FLAG_UPDATE_CURRENT);

Intent dismissIntent = new Intent(context, ExitService.class);
PendingIntent piDismiss = PendingIntent.getService(context, 0, dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT);

android.support.v4.app.NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(context)
                .setSmallIcon(R.mipmap.ic_launcher) 
               .setContentTitle(context.getString(R.string.app_name))
                  .setContentText(context.getString(R.string.ongoing_short_text))
                .setCategory(Notification.CATEGORY_SERVICE)
                .setPriority(Notification.PRIORITY_MAX)
                .setVisibility(Notification.VISIBILITY_PRIVATE)
                .setContentIntent(notificationPendingIntent)
                .setAutoCancel(true)
                .setOnlyAlertOnce(true)
                .setLights(context.getResources().getColor(R.color.primary), 50, 10000)            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                .setVibrate(new long[]{0, 50})
                .setOngoing(true)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(context.getString(R.string.ongoing_long_text)))
                .addAction(R.mipmap.ic_stop, context.getString(R.string.dismiss), piDismiss);

int mNotificationId = ONGOING_NOTIFICATION_ID;
NotificationManager mNotifyMgr = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
mNotifyMgr.notify(mNotificationId, mBuilder.build());

您可以使用服务,并从中创建计时器以取消notification@has19我不想取消-只是最小化/折叠/隐藏到状态栏你的问题是你不知道如何最小化/折叠通知或计时器或两者?我想折叠通知,比如说5秒后