title: Android FCM Push Notification not received when app is closed
body: <p>I implemented FCM Push Notifications. The main problem is when app is closed, notifications not arrive when this happen on device.</p>
  <p>I tried a lot of thigs for that works; when notification sent the server response with &quot;success&quot;, but I never received.</p>
  <p>This is full code. Android, Manifiest and server.</p>
  <p>Android:</p>
  
  <pre><code>import android.app.NotificationManager;
  import android.app.PendingIntent;
  import android.content.Context;
  import android.content.Intent;
  import android.graphics.drawable.BitmapDrawable;
  import android.media.RingtoneManager;
  import android.net.Uri;
  import android.os.Bundle;
  import android.support.v4.app.NotificationCompat;
  import android.util.Log;
  import com.accionait.canje365.R;
  import com.accionait.canje365.activities.ChatActivity;
  import com.accionait.canje365.activities.HomeActivity;
  import com.accionait.canje365.constants.Constants;
  import com.google.firebase.messaging.RemoteMessage;
  import org.json.JSONException;
  import org.json.JSONObject;
  import org.json.JSONTokener;
  
  public class FirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService {
      private static final String TAG = &quot;FCM Service&quot;;
  
      @Override
      public void onMessageReceived(RemoteMessage remoteMessage) {
          super.onMessageReceived(remoteMessage);
  
          showNotification(remoteMessage);
      }
  
      private void showNotification(RemoteMessage remoteMessage) {
          Uri uriDefaultSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
  
          NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext())
          .setSmallIcon(R.mipmap.ic_notification)
          .setLargeIcon((((BitmapDrawable)getResources().getDrawable(R.mipmap.ic_notification)).getBitmap()))
          .setContentTitle(&quot;TITLE&quot;)
          .setContentText(&quot;MESSAGE&quot;)
          .setContentInfo(&quot;0&quot;)
          .setAutoCancel(true)
          .setTicker(&quot;Canje365&quot;)
          .setSound(uriDefaultSound);
  
          Intent home = new Intent(this, HomeActivity.class);
          home.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  
          PendingIntent intent = PendingIntent.getActivity(this, 0, home, PendingIntent.FLAG_UPDATE_CURRENT);
          builder.setContentIntent(intent);
  
          NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
          notificationManager.notify(1, builder.build());
      }
  }
  </code></pre>
  <p>Server:</p>
  
  <pre><code>var message = {
      to: token,
      data: {valor: 'test'}
  };
  
  fcm.send(message, function(err, response){  
      if(err) {
          console.log('Error: ' + err);
      } 
      else {
          console.log('Notificacion enviada: ', response);
      }
  });
  </code></pre>
  <p>Manifiest:</p>
  
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot; package=&quot;com.accionait.canje365&quot;&gt;
  
  &lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot; /&gt;
  &lt;uses-permission android:name=&quot;com.google.android.providers.gsf.permission.READ_GSERVICES&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.ACCESS_COARSE_LOCATION&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.ACCESS_FINE_LOCATION&quot; /&gt;
  &lt;uses-permission android:name=&quot;com.google.android.c2dm.permission.RECEIVE&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.WAKE_LOCK&quot; /&gt;
  
  &lt;application
      android:allowBackup=&quot;true&quot;
      android:icon=&quot;@mipmap/ic_launcher&quot;
      android:label=&quot;@string/app_name&quot;
      android:supportsRtl=&quot;true&quot;
      android:theme=&quot;@style/AppTheme&quot;&gt;
  
      &lt;service android:name=&quot;.sync.RunIntentService&quot; /&gt;
      &lt;service android:name=&quot;.sync.FirebaseMessagingService&quot;&gt;
          &lt;intent-filter&gt;
              &lt;action android:name=&quot;com.google.firebase.MESSAGING_EVENT&quot; /&gt;
          &lt;/intent-filter&gt;
      &lt;/service&gt;
      &lt;service android:name=&quot;.sync.FirebaseIdService&quot;&gt;
          &lt;intent-filter&gt;
              &lt;action android:name=&quot;com.google.firebase.INSTANCE_ID_EVENT&quot;/&gt;
          &lt;/intent-filter&gt;
      &lt;/service&gt;
  
      &lt;meta-data
          android:name=&quot;com.google.android.gms.version&quot;
          android:value=&quot;@integer/google_play_services_version&quot; /&gt;
      &lt;meta-data
          android:name=&quot;com.google.android.geo.API_KEY&quot;
          android:value=&quot;MY_API_KEY&quot; /&gt;
  
      &lt;activity
          android:name=&quot;.activities.MainActivity&quot;
          android:theme=&quot;@style/SplashScreenTheme&quot;&gt;
          &lt;intent-filter&gt;
              &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
              &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;activity
           android:name=&quot;.activities.HomeActivity&quot;
           android:label=&quot;@string/title_activity_login&quot;
           android:screenOrientation=&quot;portrait&quot;&gt;
      &lt;/activity&gt;
  &lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre>
  <p>What to do with this?</p>