title: Android Receive Silent Firebase Notifications
body: <p>hello i have android application and i used Firebase notification and its working good ,, now i need to receive silent push without alert or anything ,,, i tried some idea and its working when app is running but when app in background or terminated its not working ! if anyone have idea to sole this issue please tell me :) this is my code </p>
  
  <pre><code>public class MyFirebaseMessagingService extends FirebaseMessagingService {
  
      Boolean isSilent;
      String Silent = "";
  
      @Override
      public void onMessageReceived(RemoteMessage remoteMessage) {
          try {
              Bundle bundle = new Bundle();
              for (Map.Entry&lt;String, String&gt; entry : remoteMessage.getData().entrySet()) {
                  bundle.putString(entry.getKey(), entry.getValue());
                  Log.d(entry.getKey(), entry.getValue());
              }
  //            remoteMessage.getData().get("screen_id")
              if (remoteMessage.getData().size() &gt; 0) {
                  sendNotificationData(bundle.getString("data_title"), bundle.getString("data_body"), bundle.getString("screen_id"));
  
              } else if (remoteMessage.getNotification() != null) {
                  sendNotification(remoteMessage.getNotification(), bundle.getString("screen_id"));
              }
  
  
          } catch (Exception ex) {
              ex.printStackTrace();
  
          }
      }
  
      private void sendNotification(RemoteMessage.Notification notificationR, String screenId) {
          NotificationManager nManager = (NotificationManager) this.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
          Intent intentNotification = new Intent(this, MainActivity.class);
          intentNotification.putExtra("screen_id", screenId);
          Log.v("sendNotification ", " &gt;&gt;&gt;&gt;&gt;####&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;  " + screenId);
          // finish previous activity
          if (!Silent.equals("yes")) {
              intentNotification.addFlags(android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP);
              intentNotification.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
              PendingIntent pendingIntent = PendingIntent.getActivity(this, 50, intentNotification, PendingIntent.FLAG_UPDATE_CURRENT);
              NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this.getApplicationContext())
                      .setContentTitle(notificationR.getTitle())
                      .setContentText(notificationR.getBody())
                      .setSmallIcon(getNotificationIcon())
                      .setLargeIcon(icon(getApplicationContext()))
                      .setLights(Color.LTGRAY, 1000, 1000)
                      .setAutoCancel(true)
                      .setTicker(notificationR.getTitle())
                      .setContentIntent(pendingIntent)
                      .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
  
  
              Notification notification = notificationBuilder.build();
              //  '|' Binary OR Operator copies a bit if it exists in either operand. to ensure no conflict on the flags
              notification.flags = notification.flags | Notification.FLAG_SHOW_LIGHTS;
  
              nManager.notify((int) SystemClock.currentThreadTimeMillis(), notification);
  
          }
      }
  
  
      private void sendNotificationData(String dataTitle, String dataBody, String screenId) {
          NotificationManager nManager = (NotificationManager) this.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
          Intent intentNotification = new Intent(this, MainActivity.class);
          intentNotification.putExtra("screen_id", screenId);
  
  
          if (!Silent.equals("yes")) {
              intentNotification.addFlags(android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP);
              intentNotification.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
              PendingIntent pendingIntent = PendingIntent.getActivity(this, 50, intentNotification, PendingIntent.FLAG_UPDATE_CURRENT);
              NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this.getApplicationContext())
                      .setContentTitle(dataTitle)
                      .setContentText(dataBody)
                      .setSmallIcon(getNotificationIcon())
                      .setLargeIcon(icon(getApplicationContext()))
                      .setLights(Color.LTGRAY, 1000, 1000)
                      .setAutoCancel(true)
                      .setTicker(dataTitle)
                      .setContentIntent(pendingIntent)
                      .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
  
              Notification notification = notificationBuilder.build();
              //  '|' Binary OR Operator copies a bit if it exists in either operand. to ensure no conflict on the flags
              notification.flags = notification.flags | Notification.FLAG_SHOW_LIGHTS;
  
              nManager.notify((int) SystemClock.currentThreadTimeMillis(), notification);
          }
         @Override
          public boolean zzE(Intent intent) {
              isSilent = intent.hasExtra("silent");
              if (isSilent) {
                  Silent = "yes";
              }
              return super.zzE(intent);
          }
  </code></pre>
  
  <p>when app is running this code is working but at background or terminated its not working !!</p>