title: Can firebase cloud messages be detected by app in background?
body: <p>From the document on Firebase website:
  <a href="https://firebase.google.com/docs/cloud-messaging/downstream" rel="nofollow">https://firebase.google.com/docs/cloud-messaging/downstream</a></p>
  
  <p><strong>Notifications delivered when your app is in the background. In this case, the notification is delivered to the device's system tray. A user click on a notification opens the app launcher by default.</strong></p>
  
  <p>If I need to do something when my app receives cloud message and my app is in background.</p>
  
  <p>Is it possible to receive notification in custom BroadcastReceiver or Service class instead of delivering to <strong>device's system tray</strong>?</p>
  
  <p><strong>Is the only way</strong>  to set "<strong>click_action</strong>" as described in <a href="https://firebase.google.com/docs/cloud-messaging/http-server-ref#notification-payload-support" rel="nofollow">https://firebase.google.com/docs/cloud-messaging/http-server-ref#notification-payload-support</a>
  when user clicks the notification so that my app is able to be aware of that there's a cloud message arrived?</p>
  
  <p>UPDATE:</p>
  
  <p>As mentioned by <a href="https://stackoverflow.com/users/599346/tyczj">tyczj</a>, the following curl command example did this work:</p>
  
  <pre><code>curl --header "Authorization: key=$server_key" --header Content-Type:"application/json" https://fcm.googleapis.com/fcm/send -d "{\"to\": \"/topics/friendly_engage\",\"data\": {\"score\":\"123\"}}"
  </code></pre>
  
  <p>and the message will appear on the callack "onMessageReceived" in the Service class which extends from FirebaseMessagingService</p>