【问题标题】:Error in implementing push notification on Android在 Android 上实现推送通知时出错
【发布时间】:2021-08-13 07:50:58
【问题描述】:

我正在创建一个离子角度应用程序。我尝试将推送通知与电容器插件一起使用。但是我遇到了这样的错误。谁能帮帮我?

**"ERROR Error: Uncaught (in promise): Error: "PushNotifications" plugin is not implemented on android
Error: "PushNotifications" plugin is not implemented on android"**

【问题讨论】:

  • 请分享电容版本
  • "@capacitor/android": "^3.1.2", "@capacitor/core": "^3.1.2", "@capacitor/ios": "^3.1.2", "@capacitor/push-notifications": "^1.0.3",

标签: android ionic-framework push-notification capacitor


【解决方案1】:

我解决了 “ERROR 错误:未捕获(承诺中):错误:“PushNotifications”插件未在 android 上实现 错误:“PushNotifications”插件未在 android 上实现”错误请按照以下步骤操作

在 android/app 文件夹中添加 google-service.json 文件

将此代码添加到 .ts 文件中

import {
  ActionPerformed,
  PushNotificationSchema,
  PushNotifications,
  Token,
} from '@capacitor/push-notifications';
import { Platform } from '@ionic/angular';

constructor(public platform: Platform) {
    this.platform.ready().then(() => {
      this.pushAdded();
    })
  }




pushAdded() {
    // Request permission to use push notifications
    // iOS will prompt user and return if they granted permission or not
    // Android will just grant without prompting
    PushNotifications.requestPermissions().then(result => {
      if (result.receive === 'granted') {
        // Register with Apple / Google to receive push via APNS/FCM
        PushNotifications.register();
      } else {
        // Show some error
      }
    });

    PushNotifications.addListener('registration', (token: Token) => {
      alert('Push registration success, token: ' + token.value);
    });

    PushNotifications.addListener('registrationError', (error: any) => {
      alert('Error on registration: ' + JSON.stringify(error));
    });

    PushNotifications.addListener(
      'pushNotificationReceived',
      (notification: PushNotificationSchema) => {
        alert('Push received: ' + JSON.stringify(notification));
      },
    );

    PushNotifications.addListener(
      'pushNotificationActionPerformed',
      (notification: ActionPerformed) => {
        alert('Push action performed: ' + JSON.stringify(notification));
      },
    );
  }

【讨论】:

  • 我已经添加了这些更改。但不幸的是,仍然出现同样的错误。
【解决方案2】:

我已通过删除 android 文件夹并重新添加它来解决此问题。然后它起作用了。感谢 Ravi Ashara 的帮助。

【讨论】:

    【解决方案3】:

    检查项目中的 MainActivity.java。在 Capacitor 的最新版本中,您必须删除代码“onCreate”。

    见:https://capacitorjs.com/docs/updating/3-0#switch-to-automatic-android-plugin-loading

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多