Android ongoing notification - auto collapse/hide/minimize to status bar only (not cancel)
<p>I'm building an ongoing notification. When the notification is fired - it shows on top of the display until the user swipes it, and then the notification is displayed only in the status bar. </p>

<p>How can I set timer so that the notification will automatically collapsed to be only in the status bar? e.g. so the user won't need to swipe it in order to remove it from main display? NOT CANCEL - just minimize to status bar.</p>

<p>The code below contains the ongoing notification with it's properties, and 2 actions: Click on the body open the app, click on the button close the notification.</p>

<pre><code>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());
</code></pre>