> ## Documentation Index
> Fetch the complete documentation index at: https://docs.supernote.com/llms.txt
> Use this file to discover all available pages before exploring further.

# hasPermission

> 查询插件是否已拥有指定权限。

```ts theme={null}
hasPermission(permission: string): Promise<number>;
```

**参数**

| 参数           | 类型       | 说明                                                                                                                                |
| ------------ | -------- | --------------------------------------------------------------------------------------------------------------------------------- |
| `permission` | `string` | 权限名称，支持：`plugin.permission.FILE:READ`、`plugin.permission.FILE:WRITE`、`plugin.permission.FILE:DELETE`、`plugin.permission.INTERNET` |

<Note>
  关于文件访问权限：

  1. 插件默认拥有私有目录 `/data/data/com.ratta.supernote.pluginhost/files/plugins/<pluginID>` 的读取、写入、删除权限。
  2. `sdcard` 目录下 `Document`、`EXPORT`、`INBOX`、`MyStyle`、`Note`、`SCREENSHOT` 这几个目录，读取、写入、删除权限默认都不具备，需要分别申请 `plugin.permission.FILE:READ`、`plugin.permission.FILE:WRITE`、`plugin.permission.FILE:DELETE` 后才能使用；外接 SD 卡、OTG 等外部存储设备的访问同样受这三种权限管控；除此之外的其他目录，无论是否申请相关权限，都无法获得读取、写入、删除权限。
</Note>

**返回**

* `Promise<number>`：返回权限状态，`0` 表示未授予该权限，无法使用；`1` 表示已授予该权限，可以使用

**异常**

* 当 `permission` 不是非空字符串时，会抛出参数校验异常
* 当 `permission` 不在支持列表内时，会抛出异常（错误码 `1502`）

权限体系总览、每种权限对应哪些接口，参见[插件权限](/zh/plugin-base/permission)。

## 示例

```ts wrap theme={null}
import { PluginManager } from 'sn-plugin-lib';

/**
 * 查询插件写文件权限状态的示例。
 */
export async function exampleHasPermission() {
  const permission = 'plugin.permission.FILE:WRITE';
  const status = await PluginManager.hasPermission(permission);
  return status;
}
```
