Search code examples
androidfirebasevue.jsionic-framework

Ionic Capacitor "PushNotifications" plugin is not implemented on android


I have a problem when a try to request permissions with @capacitor/push-notifications plugin. I followed every step described in the README and I'm using Ionic and Vue 3.

This is the package.json:

...
    "@capacitor/android": "^3.2.0",
    "@capacitor/core": "^3.2.0",
    "@capacitor/push-notifications": "^1.0.3",
    "@ionic/vue": "^5.4.0"
...

This is the method that requests the permissions:

requestFCMPermissions(context: AuthContext) {
      PushNotifications.requestPermissions().then(result => {
        if (result.receive === "granted") {
          PushNotifications.register();
          ...
        } else {
          ...
        }
      });
      ...
}

Of course this does not work when a try by Web, but, when I assembly an APK and profile that, it responses me an error in console log:

 "PushNotifications" plugin is not implemented on android

Anyone know why? Thanks!


Solution

  • Resolved my issue editing the MainActivity.java file:

    public class MainActivity extends BridgeActivity {
      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
     
        // Initializes the Bridge
        this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
          // Additional plugins you've installed go here
          //...
          add(com.capacitorjs.plugins.pushnotifications.PushNotificationsPlugin.class);
        }});
      }
    }
    

    but this is not specified in any tutorial, so it could be something for my configuration.