Search code examples
androidfirebase-cloud-messagingionic4capacitor

Capacitor doesn't recive android specific push-notifications


I try to implement push-notifications to my Ionic4-Capacitor-App.

In the app I have this code:

PushNotifications.register();
PushNotifications.createChannel({ id: '1', description: '2019', importance: 2, name: '2019'});
PushNotifications.addListener('pushNotificationReceived', (notification) => {
    console.debug(JSON.stringify(notification));
});

With POSTMAN I try to send the following message:

{
    "to": "<User-Token>",
    "notification": {
        "title": "Default Title",
        "body": "Default Body"
    },
    "android": {
        "notification": {
            "title": "Android Title",
            "body": "Android Title",
            "channel_id": "1"
        }
    }
}

Here is the documentation I used.

The notification I recive has "Default Title" as a title and "Default Body" as a body. I expected it to have "Android Title" and "Android Body". Additionally, the notification is not pushed to channel 1, but to Miscellaneous.

When I leave out the "root" notification part, no notification is displayed at all.


Solution

  • For everyone who faces the same problem: Here are the configuration steps I made to send firebase cloud messages via Postman.

    Google-Cloud Configuration:

    1. Go To: https://console.cloud.google.com/apis/credentials/consent
    2. Add getpostman.com to the authorized domains
    3. Go To: https://console.cloud.google.com/apis/credentials
    4. Add a new OAuth-Client-ID
    5. Select Webapplication and give it a name.
    6. Set authorized redirect-URL to https://www.getpostman.com/oauth2/callback and save.
    7. Download Json for this account

    POSTMAN Configuration:

    1. Set Request-Type to POST
    2. Enter the url: https://fcm.googleapis.com/v1/projects/{your-firebase-project-name}/messages:send
    3. Go to Authorization, select type OAuth 2.0 and click "Get New Access Token"
    4. Grant-Type Authorization Code
    5. Callback URL: https://www.getpostman.com/oauth2/callback
    6. Auth URL: [auth_uri from the json File]
    7. Access Token URL: [token_uri from the json File]
    8. Client ID: [client_id from the json File]
    9. Client Secret: [client_secret from the json File]
    10. Scope: https://www.googleapis.com/auth/firebase.messaging
    11. State: [empty]
    12. Client Authentication: Send as Basic Auth header

    When you have done these steps, you should be able to Send messages as described in this documentation: https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages/send