title: Firebase Push Notification
body: <p>I implemented Firebase for push notification in my Android app. I implemented two services for register the token and for create the notification when it is detected. When my app is launch it's working but when my app is closed it doesn't working. </p>
  
  <pre><code>public class FirebaseinstanceIdService extends FirebaseInstanceIdService {
  
      @Override
      public void onTokenRefresh() {
          String refreshedToken = FirebaseInstanceId.getInstance().getToken();
          Log.e("Firebase", refreshedToken);
          MainActivity.setFirebaseToken(refreshedToken);
      }
  
  }
  
  public class MyFirebaseMessageService extends FirebaseMessagingService {
  
      private static final String TAG = "MyFirebaseMsgService";
  
      @Override
      public void onMessageReceived(RemoteMessage remoteMessage) {
          //Displaying data in log
          //It is optional
          Log.e(TAG, "From: " + remoteMessage.getFrom());
          Log.e(TAG, "Notification Message Body: " + remoteMessage.getData().get("title"));
  
          //Calling method to generate notification
          sendNotification(remoteMessage.getData());
      }
  
      //This method is only generating push notification
      //It is same as we did in earlier posts
      private void sendNotification(Map&lt;String, String&gt; notification) {
          Intent intent = new Intent(this, MainActivity.class);
          intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
          PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
              PendingIntent.FLAG_ONE_SHOT);
  
          Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
          NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
              .setSmallIcon(R.mipmap.ic_launcher)
              .setContentTitle(notification.get("title"))
              .setContentText(notification.get("body"))
              .setAutoCancel(true)
              .setSound(defaultSoundUri)
              .setContentIntent(pendingIntent);
  
           NotificationManager notificationManager =
              (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  
          notificationManager.notify(0, notificationBuilder.build());
      }
  }
  </code></pre>
  
  <p>And my manifest :</p>
  
  <pre><code>    &lt;service
          android:name=".FirebaseinstanceIdService"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="com.google.firebase.INSTANCE_ID_EVENT"/&gt;
          &lt;/intent-filter&gt;
      &lt;/service&gt;
      &lt;service
          android:name=".MyFirebaseMessageService"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="com.google.firebase.MESSAGING_EVENT"/&gt;
          &lt;/intent-filter&gt;
      &lt;/service&gt;
  </code></pre>
  
  <p>And my request :</p>
  
  <pre><code>{
      "to": "ex1CtVz5bbE:APA91bHiM_BCun62A9iCobF1yV26Dwn-hYCDhkYPoWEG5ZdqH0P28UsE5q1v7QibwAX7AJ290-9en9L6f548_2b7WEbJ8RPEWlIotLczjjCP7xEOWqeJk6Iz44vilWYvdu4chPwfsvXD",
      "data": {
          "title": "Notification",
          "body": "Message",
      }
  }
  </code></pre>
  
  <p>I already found a few solutions in StackOverflow but it doesn't work in my case. I have an API Rest which call the API Request Post : <a href="https://fcm.googleapis.com/fcm/send" rel="nofollow">https://fcm.googleapis.com/fcm/send</a></p>
  
  <p>So, there is my question : Does Firebase handle push notification when the app is closed and how to ? </p>
  
  <p>Thank you for your answers</p>