# 集成 Cordova Huawei 插件

## 集成 Cordova 插件

按照 [集成 Cordova 插件](/zh/developer/pushwoosh-sdk/cross-platform-frameworks/cordova/integrating-cordova-plugin/) 中描述的步骤，将 Cordova 插件集成到您的项目中。

## 通过 AppGallery Connect 配置华为服务

1. 前往 [AppGallery Connect -> 项目列表](https://developer.huawei.com/consumer/en/service/josp/agc/index.html#/myProject) 并选择要配置的项目。

2. 在“应用信息”部分，点击 **agconnect-services.json** 下载配置文件。

<img src="/cordova-integrating-cordova-huawei-plugin-1.webp" alt=""/>

3. 将下载的文件放入您的 Android Studio 项目中 (`YOUR_PROJECT/app/agconnect-services.json`)。

<img src="/cordova-integrating-cordova-huawei-plugin-2.webp" alt=""/>

## 生成签名证书指纹

1. 在 Android Studio 中，前往 View > Tool Windows > Gradle。

<img src="/cordova-integrating-cordova-huawei-plugin-3.webp" alt=""/>

2. 在打开的窗口中，前往 app > Tasks > android > signingReport。

<img src="/cordova-integrating-cordova-huawei-plugin-4.webp" alt=""/>

3. 从您的发布密钥库中复制 SHA-256。

<img src="/cordova-integrating-cordova-huawei-plugin-5.webp" alt=""/>

您也可以添加来自调试密钥库的 SHA-256 用于测试。

4. 在 [AppGallery Connect 项目列表](https://developer.huawei.com/consumer/en/service/josp/agc/index.html#/myProject) 中选择您的项目。

5. 将 SHA-256 粘贴到 **SHA-256 证书指纹** 字段中。

请注意，指纹处理最多可能需要 10 分钟。

## 在 Pushwoosh 中配置华为服务

按照指南为您的 Pushwoosh 项目配置华为平台：[配置华为](/zh/developer/first-steps/connect-messaging-services/huawei-configuration/)。

将 **agconnect-services.json** 添加到 **android/app**。

## 添加华为仓库

将 [maven 仓库](https://developer.huawei.com/repo/) 添加到您项目的 **android/repositories.gradle** 和 **android/app/repositories.gradle** 文件中。

<img src="/cordova-integrating-cordova-huawei-plugin-6.webp" alt=""/>

## 添加依赖项

1. 将 **classpath "com.huawei.agconnect:agcp:1.2.1.301"** 添加到 **android/build.gradle** 文件的 **buildScript/dependencies** 中。

<img src="/cordova-integrating-cordova-huawei-plugin-7.webp" alt=""/>

2. 将 **apply plugin: 'com.huawei.agconnect'** 和 **implementation "com.huawei.hms:push:6.1.0.300** 添加到 **android/app/build.gradle** 中。

## 启用推送通知

在您的 JavaScript 代码中，在执行 **onDeviceReady** 之前添加 **enableHuaweiPushNotifications**：

```javascript
var pushNotification = cordova.require("pushwoosh-cordova-plugin.PushNotification");

pushNotification.enableHuaweiPushNotifications();
pushNotification.onDeviceReady({
    projectid: "GOOGLE_PROJECT_ID",
    appid: "PUSHWOOSH_APP_ID",
    serviceName: ""
});
```

## 与我们分享您的反馈

您的反馈有助于我们创造更好的体验，因此如果您在 SDK 集成过程中遇到任何问题，我们非常希望听到您的声音。如果您遇到任何困难，请随时[通过此表单](https://docs.google.com/forms/d/e/1FAIpQLSd\_0b8jwn-V\_JmoPLIxIFYbHACCQhrzidOZV3ELywoQPXRSxw/viewform)与我们分享您的想法。