title: Android Firebase background notification not firing
body: <p>I'm developing an Android App that receives push notifications from Firebase.</p>
  
  <p>I can get the token and send push notifications from Postman without any problem.</p>
  
  <p>If the App is in foreground everything works as expected and I receive the payload in the onMessageReceived (I tested with various payloads). </p>
  
  <p>But if I close the App it don't receive nothing. I tried with a lot of payloads, and I read all the documentation (diference between data and notification in payload).</p>
  
  <p>Here's my classes that my project uses:</p>
  
  <p>1 - The class that extends FirebaseMessagingService</p>
  
  <pre><code>public class MyFirebaseMessagingService extends FirebaseMessagingService {
  
  private static final String TAG = "Android Push App";
  
  @Override
  public void onMessageReceived(RemoteMessage remoteMessage) {
      sendNotification("Received notification");
  }
  
  private void sendNotification(String messageBody) {
      Intent intent = new Intent(this, MainActivity.class);
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
              PendingIntent.FLAG_ONE_SHOT);
  
      Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
      NotificationCompat.Builder notificationBuilder =
              new NotificationCompat.Builder(this)
                      .setSmallIcon(R.drawable.push_icon)
                      .setContentTitle("FCM Message")
                      .setContentText(messageBody)
                      .setAutoCancel(true)
                      .setSound(defaultSoundUri)
                      .setContentIntent(pendingIntent);
  
      NotificationManager notificationManager =
              (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  
      notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
  }
  </code></pre>
  
  <p>2 - The class that is responsible for get the token</p>
  
  <pre><code>public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
  
  private static String TAG = "Android Push App";
  
  @Override
  public void onTokenRefresh() {
      String refreshedToken = FirebaseInstanceId.getInstance().getToken();
      sendRegistrationToServer(refreshedToken);
  }
  
  private void sendRegistrationToServer(String token) {
      Log.d(TAG, "Did obtained token");
      Log.d(TAG, token);
  }
  </code></pre>
  
  <p>3 - My Manifest:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:supportsRtl="true"
      android:theme="@style/AppTheme"&gt;
      &lt;activity android:name=".MainActivity"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
              &lt;action android:name="FIREBASE_ACTIVITY" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;category android:name="android.intent.category.DEFAULT" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  
      &lt;service android:name=".push.core.MyFirebaseInstanceIDService"&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=".push.core.MyFirebaseMessagingService"
          android:enabled="true"
          android:exported="true"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="com.google.firebase.MESSAGING_EVENT" /&gt;
          &lt;/intent-filter&gt;
      &lt;/service&gt;
  
      &lt;meta-data
          android:name="com.google.firebase.messaging.default_notification_icon"
          android:resource="@drawable/push_icon" /&gt;
  
      &lt;meta-data android:name="com.google.firebase.messaging.default_notification_color"
          android:resource="@color/colorAccent" /&gt;
  
  &lt;/application&gt;
  </code></pre>
  
  <p>4 - The MainActivity</p>
  
  <pre><code>public class MainActivity extends Activity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      if (getIntent().getExtras() != null) {
          for (String key : getIntent().getExtras().keySet()) {
              Object value = getIntent().getExtras().get(key);
              Log.d("MainActivity", "Key: " + key + " Value: " + value);
          }
      }
  }
  </code></pre>
  
  <p>5 - Finally I tried this payload in the Postman</p>
  
  <p>POST <a href="https://fcm.googleapis.com/fcm/send" rel="nofollow noreferrer">https://fcm.googleapis.com/fcm/send</a>
  Content-Type application/json
  Authorization key=AIzaSy(...)kY</p>
  
  <p>JSON Body (the examples I tried):</p>
  
  <pre><code>{
  "to": "dxe0RDKbP...m9Uc","notification" : {
    "body" : "great match!",
    "title" : "Portugal vs. Denmark",
    "icon" : "push_icon",
    "sound" : "default"
  }}
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>{
  "to": "dxe0RDKbP...m9Uc","notification" : {
    "body" : "great match!",
    "title" : "Portugal vs. Denmark",
    "icon" : "push_icon",
    "sound" : "default"
  }}
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>{
  "to": "d3j-9OJ6R...C6w",
  "notification" : {
      "title": "title",
      "body": "body"
  },
  "data": {
      "tipo": "normal"
  }}
  </code></pre>
  
  <p>Also added the "priority" key and it doesn't work.</p>
  
  <p>What I'm I doing wrong?</p>
  
  <p>Thanks for all the help you can gave to me :)</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Now it's working.</p>
  
  <p>There was a conflict between the FireBaseMessagingService and a Geofence Push that is running (fired by the App).</p>
  
  <p>After removed this Geofence service everything works as expected.</p>
  
  <p>Also use the <em>notification</em> and <em>data</em> keys in the payload of the push.</p>
  
  <p>Thanks</p>