# @capacitor-community/security-provider 中文文档

规范地址：https://npmcn.com/package/%40capacitor-community/security-provider/

版本：7\.0\.0
npm 元数据更新时间：2026-10-23T21:48:02.453Z
中文译文更新时间：2026-11-09T07:07:14.708Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40capacitor-community/security-provider
原文对照：https://npmcn.com/package/%40capacitor-community/security-provider/?lang=original
项目主页：https://github.com/capacitor-community/security-provider#readme
源码仓库：https://github.com/capacitor-community/security-provider

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：31.6 kB，27 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：0 个
- peer 依赖：@capacitor/core \>=7\.0\.0
- 首次发布：2023-05-08T22:23:20.574Z
- 最新版本发布：2025-02-16T17:32:19.924Z
- 近 30 天下载量：4372（2026-10-09 至 2026-11-07，npm 官方下载统计）
- 已发布版本数：5（近 12 个月 0 个）

## 中文简介

具有检查和更新Android安全提供者方法的电容插件

## 安装

```sh
npm install @capacitor-community/security-provider
```

也可以使用：`pnpm add @capacitor-community/security-provider`、`yarn add @capacitor-community/security-provider`、`bun add @capacitor-community/security-provider`

## README

  
![](https://user-images.githubusercontent.com/236501/85893648-1c92e880-b7a8-11ea-926d-95355b8175c7.png)

### Android 安全提供者

**`@capacitor-community/security-provider`**

检查并更新 Capacitor app中的Android安全提供商.

![](https://img.shields.io/maintenance/yes/2024?style=flat-square) [![](https://img.shields.io/npm/l/@capacitor-community/security-provider?style=flat-square)](https://www.npmjs.com/package/@capacitor-community/security-provider)  
[![](https://img.shields.io/npm/dw/@capacitor-community/security-provider?style=flat-square)](https://www.npmjs.com/package/@capacitor-community/security-provider) [![](https://img.shields.io/npm/v/@capacitor-community/security-provider?style=flat-square)](https://www.npmjs.com/package/@capacitor-community/security-provider) [![](https://img.shields.io/badge/all%20contributors-1-orange?style=flat-square)](https://npmcn.com/package/%40capacitor-community/security-provider/#readme-contributors-)

## 关于

具有检查和更新Android安全提供商方法的电容插件.

Android依靠安全提供商提供安全的网络通信. 然而,不时在缺省担保提供人中发现有弱点。 为了防范这些弱点,Google Play服务提供了一种自动更新设备安全供应商的方法来防范已知的被利用. 通过调用Google Play服务方法,您可以帮助确保您的应用程序运行在一个有最新更新的设备上,以防范已知的被利用.

例如,在OpenSSL(CVE-2014-0224)中发现了一种脆弱性,这种脆弱性可以让应用打开来进行可解密交通的上行道攻击,而任何一方都不知情. Google Play服务版本 5.0提供固定,但应用程序必须检查是否安装了这个固定. 通过使用Google Play服务方法,您可以帮助确保您的应用程序运行在能够防范袭击的设备上.

## 安装

```bash
npm install @capacitor-community/security-provider
npx cap sync
```

## 使用量

```typescript
import { CapacitorSecurityProvider, SecurityProviderStatus } from '@capacitor-community/security-provider';
...
    const result = await CapacitorSecurityProvider.installIfNeeded();
    if (result.status !== SecurityProviderStatus.Success && result.status != SecurityProviderStatus.NotImplemented) {
        // Do not proceed. The Android Security Provider failed to verify / install.
    }
```

见 [样本控制器 5 应用程序](https://github.com/dtarnawsky/android-security-provider) 使用此插件.

## API 密码

-   [`installIfNeeded()`](https://npmcn.com/package/%40capacitor-community/security-provider/#readme-installifneeded)
-   [数字](https://npmcn.com/package/%40capacitor-community/security-provider/#readme-enums)

### 安装ifNeed ()

```typescript
installIfNeeded() => Promise<{ status: SecurityProviderStatus; }>
```

**回返情况:** `Promise<{ status: [SecurityProviderStatus](https://npmcn.com/package/%40capacitor-community/security-provider/#readme-securityproviderstatus); }>`

* * *

### 数字

#### 安全状况

| 成员 | 数值 | 说明 |
| --- | --- | --- |
| **`Success`** | `'Success'` | 这表明供应商已更新或已成功更新 |
| **`NotImplemented`** | `'NotImplemented'` | 这将发生在iOS和Web上,因为这些平台不能叫Android安全提供商 |
| **`GooglePlayServicesRepairableException`** | `'GooglePlayServicesRepairableException'` | 表示Google Play服务过时,已禁用等. 如果返回, 本地对话框将通知并提示用户更新 . |
| **`GooglePlayServicesNotAvailableException`** | `'GooglePlayServicesNotAvailableException'` | 表示无法恢复的错误; 提供者无法安装最新的提供者 。 您应该中止应用程序的运行 . |

## 常见问题

### @capacitor-community/security-provider 是什么？

具有检查和更新Android安全提供者方法的电容插件

### 如何安装 @capacitor-community/security-provider？

在项目目录运行 npm install @capacitor-community/security-provider，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：@capacitor/core（\>=7\.0\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @capacitor-community/security-provider 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @capacitor-community/security-provider 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @capacitor-community/security-provider 可以商用吗？

@capacitor-community/security-provider 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @capacitor-community/security-provider 的下载量有多少？

根据 npm 官方下载统计，@capacitor-community/security-provider 在 2026/10/09 – 2026/11/07 这 30 天内被下载 4,372 次，日均约 146 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @capacitor-community/security-provider 还在维护吗？

最新版本 7\.0\.0 发布于 2025/02/17（1\.7 年前）；至今共发布 5 个版本，其中过去 12 个月发布了 0 个；首次发布于 2023/05/09。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

