title: FCM returning MismatchSenderId
body: <p>I think I have completed every step necessary to convert my messaging app from GCM to FCM but it is not working.  FCM is currently returing MismatchSenderId.</p>
  
  <p>I have the following services defined in my AndroidManifest.xml .  </p>
  
  <pre><code>&lt;service
           android:name=".MyFcmListenerService"&gt;
           &lt;intent-filter&gt;
               &lt;action android:name="com.google.firebase.MESSAGING_EVENT" /&gt;
           &lt;/intent-filter&gt;
       &lt;/service&gt;
       &lt;service
           android:name=".MyFirebaseInstanceIDService"&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>Right now the following listener code never gets executed, of course, because the message is getting rejected</p>
  
  <pre><code>public class MyFcmListenerService extends FirebaseMessagingService {
      @Override
      public void onMessageReceived(RemoteMessage message)
      {
          String from = message.getFrom();
          Map data = message.getData();
          String debug = "what is in data?";
          //todo Process incoming message here
      }
  </code></pre>
  
  <p>The code for the instance Id service is as follows . . .</p>
  
  <pre><code>public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService
  {
      private static final String TAG = "MyFirebaseIIDService";
      @Override
      public void onTokenRefresh() {
  
          String regToken = FirebaseInstanceId.getInstance().getToken();
          //store token in shared memory
          SPHelper.setTempString(GlobalStuff.GCT, "fcmtoken", regToken);
      }
  }
  </code></pre>
  
  <p>The sender id on my firebase console matches the project number in my google-services.json.  They are both the same 12 digit number.  I defined two variants to the console: com.deanblakely.myapp and com.deanblakely.myapp.debug and those two variants are also included in my json file.</p>
  
  <p>BTW after all work was done I again downloaded google-services.json to make sure it was identical to the one I had.  It was not.  The most recent json had this one additional line but it had no effect on my issue.</p>
  
  <pre><code>"storage_bucket": "optimal-xxxxxx-824.appspot.com"
  </code></pre>
  
  <p>The following C# code runs on my server and does the Post to FCM.  It is my same GCM posting code except for the FCM URL. (“regid” is actually the FCM token of the target phone).</p>
  
  <pre><code>   private string FCMPostToPhone(string regid, string apiKey, string postData)
      {
  
      //This posts the message to Firebase Cloud Messaging (FCM)
  
      string PostString = "{ \"registration_ids\": [ \"" + regid + "\" ], \"data\":" + postData + "}";
  
      byte[] byteArray = Encoding.UTF8.GetBytes(PostString);
      Logger.log("Post to FCM = " + PostString);
      HttpWebRequest Request = (HttpWebRequest)WebRequest.Create("https://fcm.googleapis.com/fcm/send");
      Request.Method = "POST";
      Request.KeepAlive = false;
      Request.ContentType = "application/json";
      Request.Headers.Add(string.Format("Authorization: key={0}", apiKey));
      Request.ContentLength = byteArray.Length;
      Stream dataStream = Request.GetRequestStream();
      dataStream.Write(byteArray, 0, byteArray.Length);
      dataStream.Close();
      //  SEND MESSAGE
      try
      {
          WebResponse Response = Request.GetResponse();
          HttpStatusCode ResponseCode = ((HttpWebResponse)Response).StatusCode;
          if (ResponseCode.Equals(HttpStatusCode.Unauthorized) || ResponseCode.Equals(HttpStatusCode.Forbidden))
          {
              Logger.log("Unauthorized - need new token");
  
          }
          else if (!ResponseCode.Equals(HttpStatusCode.OK))
          {
              Logger.log("Response from web service isn't OK");
          }
          //HttpStatusCode.
          StreamReader Reader = new StreamReader(Response.GetResponseStream());
          string responseLine = Reader.ReadToEnd();
          Reader.Close();
          Logger.log("Post Response from GCM = " + responseLine);
  </code></pre>
  
  <p>The following is the actual logs made from the above code showing the MimatchSenderId error from FCM (although it says GCM).  (the message looks weird because it’s all encrypted).</p>
  
  <blockquote>
    <p>6/25/2018 12:08:43 PMDBAWP7  Post to GCM = { "registration_ids": [
    "eBGLX0_IzPI:APA91bGKIRz6Qu-W-OrFjB2vY5_yS8EanepiZjkz83borQw2bvHwWLvuzNSQAr3WStWDY2ijALLBAnGgq64jWfW2YHMkAImgEKdAWZvgj7m1MXgpB9_2zH7uRdLUQNAG2jmEK3YzHYxgJBQTq_Cgz1mOpNxbDeLU3A"
    ],
    "data":{"Message":"9FnAod3oemeAH0iw8oojG5WNnmcqmiGLjIjESex0mHY\u003d\n","aeskey":"tSFErur1I8O1ADjhP5UTNdpryNwVw156bTr9Hz70//jpJoUIcEE41KOjkrt8yKpQQpSgqgj2A2/GMDXOzIN2wEVnKRqJir7Ylp85DHuj2Z0swOnEuYPUTHXv3z6iQXZlVrw65EP6TrpqyAnCppejqxuDAC2wtQI1zpfRWIlBs9sSnsucOxtpBEbIAo2AdWaBAnL9JtzuMc/xG/IzLKFsH5+DBOwQccWM4MfK8RbpVmS0RUxzSBbkUi2RBVW86ZP6vzAdliR9qCRVzr2K/x7/7IvCdmpzT5V2LM0xBiXA0Vr8BBBOygXVxM4HYplNS8C7C6eSeb/JzoGD8qj/hMvDTw\u003d\u003d","fromLang":"English","fromPhoneKey":"gbsamsung","fromUsername":"","mine":"y","subActive":"n","timeSentGMT":"2018-06-25
    19:08:43","toPhoneKey":"emulator27","tran":"##03"}}</p>
    
    <p>6/25/2018 12:08:44 PMDBAWP7  Post Response from GCM =
    {"multicast_id":5172924974567668915,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"MismatchSenderId"}]}</p>
  </blockquote>
  
  <p>Nowhere in my project do I do anything with SENDER_ID in my code.</p>