title: How to get text of Stacked Notifications in Android
body: <p>The question is how to get the TEXT (not title) field of all incoming notifications when they get stacked (like in Whatsapp). </p>
  
  <p><img src="https://i.stack.imgur.com/wBLDe.jpg" alt="enter image description here"></p>
  
  <pre><code>public class NLService extends NotificationListenerService {
  public void onNotificationPosted(StatusBarNotification sbn) {
  
      Log.v(Constants.TAG_notifs,
              "------------------------- in onNotificationPosted(), Notification Text = "
                      + sbn.getNotification().tickerText);
  
  
      Bundle extras = sbn.getNotification().extras;
  
      if (extras.containsKey("android.text")) {
          if (extras.getCharSequence("android.text") != null) {
              String text = extras.getCharSequence("android.text").toString();
              Log.v(Constants.TAG_notifs,
                      "------------------------- in onNotificationPosted(), Bundle.text != NULL, so here it is = "
                              + text);
          } 
      }
  
      if (extras.containsKey("android.title")) {
          Log.v(Constants.TAG_notifs,
                  "------------------------- in onNotificationPosted(), Bundle android.title = "
                          + extras.getString("android.title"));
      }
  
  }
  
  @Override
  public void onNotificationRemoved(StatusBarNotification sbn) {
      //super.onNotificationRemoved(sbn);
  }
  </code></pre>
  
  <p>}
  The first time when a Whatsapp notification arrives from a single user this line (<strong>String text = extras.getCharSequence("android.text").toString();</strong>) is successfully able to read <strong>text</strong>, but after that when more messages come in and notifications get stacked (like in the picture shown above), the variable <strong>text</strong> is always NULL.</p>
  
  <p>This must be possible because <a href="https://play.google.com/store/apps/details?id=com.squanda.swoop.app" rel="noreferrer">this app</a> is doing it, tested it. It is getting the text of each and every app.</p>
  
  <p><em>Added Incentive</em>: If you know the answer or things to try, there is another question which looks similar question <a href="https://stackoverflow.com/questions/28047767/notificationlistenerservice-not-reading-text-of-stacked-notifications">here</a>.</p>