title: How to Programmatically close the notification tray
body: <p>I want to share the GCM notification item. The share button is responding to click events and item gets shared too. Only problem here is, Intent chooser dialog is present below the notification tray. User has to manually close the status bar and then select the app for sharing. I want to close the status bar programmatically, so that when the user clicks share, it directly shows him the dialog to choose the apps. </p>
  
  <p>I found that <code>status bar</code> service can be used to open/close the service. But it's restricted for system apps. </p>
  
  <pre><code>private void closeNotificationTray() {
          Object service = mContext.getSystemService(Context.STATUS_BAR_SERVICE);
          Method collapse;
          try {
              Class&lt;?&gt; statusBarMngr = Class.forName("android.app.StatusBarManager");
              if (Build.VERSION.SDK_INT &gt;= 17)
                  collapse = statusBarMngr.getMethod("collapsePanels");
              else
                  collapse = statusBarMngr.getMethod("collapse");
              collapse.invoke(service);
          } catch (ClassNotFoundException e) {
              e.printStackTrace();
          } catch (NoSuchMethodException e) {
              e.printStackTrace();
          } catch (InvocationTargetException e) {
              e.printStackTrace();
          } catch (IllegalAccessException e) {
              e.printStackTrace();
          }
  </code></pre>
  
  <p>I used the above code. But I'm getting "STATUS_BAR_SERVICE cannot be resoloved" error. And when i added the below permision in the manifest:</p>
  
  <pre><code>&lt;uses-permission
          android:name="android.permission.STATUS_BAR" /&gt;
  </code></pre>
  
  <p>I'm getting, allowed only for system apps.It's not allowing me to use in my app. Is there any way to use <code>status bar</code>service or any other alternative?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I solved the above issue with just 2 lines of code. There is no need to call STATUS_BAR_SERVICE.</p>
  
  <pre><code>Intent it = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
      mContext.sendBroadcast(it);
  </code></pre>
  
  <p>Calling this intent will automatically closes the notification</p>