title: FCM messages is not always delivered
body: <p>I push Firebase messages from PHP and they usually get the target Android app.</p>
  <p>Nonetheless, and occasionally, a push message is not correctly delivered if the target Android mobile was inactive for some period of time. Then, if I open the app, the message is delivered immediately.</p>
  <p>I read about the Doze status; the battery optimizations; etc. I don't want to bother the user to explicitly whitelist the app.</p>
  <p>Thanks in advance !</p>
  <p>PHP:</p>
  <pre><code>    private function sendFirebaseMessage($msg, $to_uid) {
         // getting firebase token ID
         $user_token_id = DB::getInstance()-&gt;getUserFirebaseTokenId($to_uid);
         
         #API access key from Google API's Console
         define( 'API_ACCESS_KEY', 'A...7' );
         
         $fields = array
         (
                  'to'    =&gt; $user_token_id,
                  'data'  =&gt; $msg,
                  &quot;priority&quot; =&gt; &quot;high&quot;
         );
         
         $headers = array
         (
                  'Authorization: key=' . API_ACCESS_KEY,
                  'Content-Type: application/json'
         );
         #Send Reponse To FireBase Server
         $ch = curl_init();
         curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
         curl_setopt( $ch,CURLOPT_POST, true );
         curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
         curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
         curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
         curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
         $result = curl_exec($ch );
         curl_close( $ch );
         #Echo Result Of FireBase Server
         return $user_token_id . &quot;]XXX[&quot; . $result;
      }
  </code></pre>
  <p>Android/Java:</p>
  <pre><code>    @Override
      public void onMessageReceived(RemoteMessage remoteMessage) {
          super.onMessageReceived(remoteMessage);
          
          // Check if message contains a data payload.
          Map&lt;String, String&gt; data = remoteMessage.getData();
          if (data.size() &gt; 0) {
              Log.d(TAG, &quot;StorableMessage data payload: &quot; + data);
  
              if (data.containsKey(&quot;sender_id&quot;) &amp;&amp;
                      data.containsKey(&quot;sender_name&quot;) &amp;&amp;
                      data.containsKey(&quot;chat_topic&quot;)) {
  
                  if (!ChatActivity.IsVisible) {
  
                      NotifsManager.showFirebaseNotif(this,
                              data.get(&quot;sender_name&quot;),
                              data.get(&quot;sender_id&quot;),
                              data.get(&quot;chat_topic&quot;));
                  }
              }
          }
      }
  </code></pre>