FCM push notifications for Android not working direct to token


These used to work and now do not. I can’t pinpoint exactly when they stopped working.
I am using Capacitor 3 and upgraded from Capacitor 2 recently.

"@capacitor-community/fcm": "^2.0.2",
"@capacitor/push-notifications": "^1.0.9"

This is the error I get:

Unhandled error { Error: The registration token is not a valid FCM registration token
    at FirebaseMessagingError.FirebaseError [as constructor] (/workspace/node_modules/firebase-admin/lib/utils/error.js:44:28)
    at FirebaseMessagingError.PrefixedFirebaseError [as constructor] (/workspace/node_modules/firebase-admin/lib/utils/error.js:90:28)
    at new FirebaseMessagingError (/workspace/node_modules/firebase-admin/lib/utils/error.js:256:16)
    at Function.FirebaseMessagingError.fromServerError (/workspace/node_modules/firebase-admin/lib/utils/error.js:289:16)
    at Object.createFirebaseError (/workspace/node_modules/firebase-admin/lib/messaging/messaging-errors-internal.js:35:47)
    at /workspace/node_modules/firebase-admin/lib/messaging/messaging-api-request-internal.js:79:51
    at process._tickCallback (internal/process/next_tick.js:68:7)
   { code: 'messaging/invalid-argument',
      'The registration token is not a valid FCM registration token' },
  codePrefix: 'messaging' } 

Things I have tested:

  1. Tried a message to the topic from the cloud function. Works.
  2. Tried a message to the token from the cloud function. Did not work. See error above.
  3. Tried a message to the topic from the FCM console. Worked.
  4. Tried a message to the token from the FCM console. Did not work.
  5. Checked the google-service.json file against a latest version from the firebase project. Looks fine,
  6. Testing on iOS topic and token. Works fine.
  7. In Play store Setup -> App Integrity the "Upload Key Certificate" SHA-256 matches the Firebase project for the app. But the "App Signing Key Certificate" SHA-256 does not match. Is this an issue?
    enter image description here

Cloud function code:

const notification: admin.messaging.Notification = {
      title: title,
      body: body

  const message: admin.messaging.Message = {
        sound: 'default',
        icon: 'push_logo',
        color: '#000000',
          aps: {
            sound: 'default'

  return admin.messaging().send(message)

Which creates:

{ notification: { title: 'test', body: 'test' },
   { notification: { sound: 'default', icon: 'push_logo', color: '#000000' } },
  apns: { payload: { aps: [Object] } } } 

Ionic (Angular) app code:

 PushNotifications.requestPermissions().then((permission) => {
      if (permission.receive === 'granted') {
        PushNotifications.register().then(result => {
          // Register for some topics here. Code removed.
        .catch(err => {
          console.log('Push register error');

 private async saveFCMToken() {
    try {
      const result = await FCM.getToken();
      const member = this.authService.getCurrentMember();
      if (member) {
        // Save the token against the member
        await this.authService.updateMember(member.id, { fcmToken: result.token });
    } catch(err) {
      console.log('Error saving FCM token')

I have found the problem although I have no idea why this happens.
On Android if I use

import { FCM } from "@capacitor-community/fcm";
const result = await FCM.getToken();

it returns a token that DOES NOT WORK and looks like this:

However if I use

PushNotifications.addListener('registration', (token: Token) => {
      console.log('token.value', token.value)

it returns a token THAT WORKS and looks like:

On iOS await FCM.getToken() works fine.

Ah found the issue here:


It turns out it is due to the change from Capacitor 2 to Capacitor 3.

You need to use a different method for Android vs iOS in Capacitor 3.

PushNotifications.addListener('registration', async ({ value }) => {
  let token = value // Push token for Android

  // Get FCM token instead the APN one returned by Capacitor
  if (Capacitor.getPlatform() === 'ios') {
    const { token: fcm_token } = await FCM.getToken()
    token = fcm_token
  // Work with FCM_TOKEN

See here: https://github.com/capacitor-community/fcm/issues/99

Answered By – MadMac

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published