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);