androidandroid-notification-bar

How can I programmatically open/close notifications in Android?


I've searched everywhere, but can't find anything in the SDK or on Google on how to do this. I know it's possible because all the custom launchers are able to do it via a button press (LauncherPro, ADW, etc).

Thanks.


Solution

  • You can programmatically close the notification drawer by broadcasting an ACTION_CLOSE_SYSTEM_DIALOGS intent.

    This causes "temporary system dialogs" to be dismissed. From the documentation:

    Some examples of temporary system dialogs are the notification window-shade and the recent tasks dialog.

    This doesn't require any permissions, and has apparently been available since Android 1.0.

    The following code works for me on a Nexus 4 running Android 5.0:

    Intent closeIntent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
    context.sendBroadcast(closeIntent);