Home > Net >  Capacitor - floating notifications not enabled by default on Android after migration from cordova
Capacitor - floating notifications not enabled by default on Android after migration from cordova

Time:10-29

We migrated our App from Cordova to Capacitor.

For Push-Notifications on Cordova we had used the cordova-plugin-firebasex plugin.

For Capacitor replaced the Plugin with the official Push Notifications plugin and the FCM plugin (we need FCM).

When installing the App now on Android, the "Floating Notifications"-Setting for the App is disabled on default, while with the cordova plugin its enabled by default.

Any ideas what could be the cause or how we can enable the setting by default?

The general consensus is that this setting cannot be influenced by the App, but why is it then working for the cordova-plugin?

CodePudding user response:

Found the difference:

As here described, Android needs to be subscribed to at least to one Channel. The cordova-plugin does this automatically, for capacitor it must be done manually.

So add

        await PushNotifications.createChannel({
          id: '<id>',
          name: '<Name>',
          description: '<Description>',
          importance: 5,
          visibility: 1,
          lights: true,
          vibration: true,
        });

for Android after the registration.

Additionally put the following as xml file into res/values.

<?xml version='1.0' encoding='utf-8'?>
<resources>
    <string name="default_notification_channel_id"><id></string>
    <string name="default_notification_channel_name"><name></string>
</resources>

Then this must be linked in the AndroidManifest.xml:

    <meta-data
        android:name="com.google.firebase.messaging.default_notification_channel_id"
        android:value="@string/default_notification_channel_id"/>

    <meta-data
        android:name="com.google.firebase.messaging.default_notification_channel_name"
        android:value="@string/default_notification_channel_name"/>

For the <id> its the easiest to use the default id which is used in the cordova-plugin:

fcm_default_channel
  • Related