title: Firebase don't receive message when app is killed - Android Oreo
body: <p>I know that it have a lot of questions about this theme, but no one works in my project, and I don't know why.</p>
  
  <p>I'm using Firebase, if my app is OPEN or in BACKGROUND, his receive the message, but when I kill my app don't appear more.</p>
  
  <p>Using Android 8.0</p>
  
  <p>My codes:
  AndroidManifest.xml</p>
  
  <pre><code>    &lt;meta-data
          android:name="com.google.firebase.messaging.default_notification_icon"
          android:resource="@drawable/default_notification_icon" /&gt;
      &lt;meta-data
          android:name="com.google.firebase.messaging.default_notification_color"
          android:resource="@color/colorPrimary" /&gt;
      &lt;meta-data android:name="com.google.firebase.messaging.default_notification_channel_id"
          android:value="@string/default_notification_channel_id" /&gt;
  
      &lt;service
          android:name=".service.PineFirebaseMessagingService"
          android:enabled="true"
          android:exported="true"
          android:permission="com.google.android.c2dm.permission.SEND"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="com.google.firebase.MESSAGING_EVENT" /&gt;
              &lt;action android:name="com.google.android.c2dm.intent.RECEIVE" /&gt;
          &lt;/intent-filter&gt;
      &lt;/service&gt;
  
      &lt;service
          android:name=".service.PineFirebaseInstanceIDService"
          android:enabled="true"
          android:exported="true"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="com.google.firebase.INSTANCE_ID_EVENT" /&gt;
          &lt;/intent-filter&gt;
      &lt;/service&gt;
  </code></pre>
  
  <p>FirebaseMessagingService.java</p>
  
  <pre><code>@Override
  public void onMessageReceived(RemoteMessage remoteMessage) {
  
      channelId = getString(R.string.default_notification_channel_id);
  
      Log.i("Msg", "Message received [" + remoteMessage.getData() + "]");
  
      Intent intent = new Intent(this, HomeActivity.class);
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      PendingIntent pendingIntent = PendingIntent.getActivity(this, id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
  
      Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
      NotificationCompat.Builder notificationBuilder = new
              NotificationCompat.Builder(this, channelId)
              .setSmallIcon(R.drawable.default_notification_icon)
              .setColor(ContextCompat.getColor(this, R.color.colorPrimary))
              .setContentTitle(remoteMessage.getData().get("title"))
              .setContentText(remoteMessage.getData().get("message"))
              .setAutoCancel(true)
              .setContentIntent(pendingIntent)
              .setSound(defaultSoundUri);
  
      NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
      if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.O) {
          NotificationChannel mChannel = new NotificationChannel(
                  channelId,
                  remoteMessage.getData().get("title"),
                  NotificationManager.IMPORTANCE_HIGH);
          mChannel.setDescription(remoteMessage.getData().get("message"));
          mChannel.enableLights(true);
          mChannel.enableVibration(true);
          mChannel.setLightColor(Color.BLUE);
          notificationManager.createNotificationChannel(mChannel);
          notificationManager.cancel(id);
      }
  
      notificationManager.notify(id, notificationBuilder.build());
  }
  </code></pre>
  
  <p>FirebaseInstanceIdService.java</p>
  
  <pre><code>@Override
  public void onTokenRefresh() {
  
      super.onTokenRefresh();
      String refreshedToken = FirebaseInstanceId.getInstance().getToken();
      Log.d("Token", "Refreshed token: " + refreshedToken);
  }
  </code></pre>
  
  <p>Code in C# to send the push</p>
  
  <pre><code>async Task SendPushAndroidAsync(Device device, InArgumentRequest push, Notification notification)
      {
          var applicationID = configuration["Push:Google:ApplicationKey"];
  
          var data1 = new
          {
              to = DeviceIdEnviroment(device.Token, true),
              android = new {
                  priority = "normal"
              },
              data = new
              {
                  notificationId = notification.Id,
                  title = notification.Title,
                  message = notification.Message,
                  type = notification.Type,
                  date = notification.DateCreated.ToString("dd/MM/yyyy HH:mm"),
                  android_channel_id = "channelidandroid"
              }
          };
          try
          {
              var jsonBody = JsonConvert.SerializeObject(data1);
  
              using (var httpRequest = new HttpRequestMessage(HttpMethod.Post, "https://fcm.googleapis.com/fcm/send"))
              {
                  httpRequest.Headers.TryAddWithoutValidation("Authorization", "key=" + applicationID);
                  httpRequest.Content = new StringContent(jsonBody, Encoding.UTF8, "application/json");
  
                  using (var httpClient = new HttpClient())
                  {
                      var result = await httpClient.SendAsync(httpRequest);
  
                      if (result.IsSuccessStatusCode)
                      {
                          await UpdateStatusNotification(notification, true);
                      }
                      else
                      {
                          await UpdateStatusNotification(notification, false, result.ReasonPhrase);
                      }
                  }
              }
          }
          catch (Exception ex)
          {
              string error = ex.InnerException.Message;
              await UpdateStatusNotification(notification, false, error);
          }
      }​
  </code></pre>
  
  <p>Thanks!</p>