https://github.com/xenonbyte/permify
Simplify Android runtime and special permissions requests
https://github.com/xenonbyte/permify
android android-permissions java runtime-permissions
Last synced: 2 months ago
JSON representation
Simplify Android runtime and special permissions requests
- Host: GitHub
- URL: https://github.com/xenonbyte/permify
- Owner: xenonbyte
- License: apache-2.0
- Created: 2025-03-18T18:11:31.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-20T16:39:22.000Z (over 1 year ago)
- Last Synced: 2025-06-30T21:08:13.919Z (12 months ago)
- Topics: android, android-permissions, java, runtime-permissions
- Language: Java
- Homepage:
- Size: 128 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README-zh.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# permify
`permify` 是一个 Android 权限请求库,提供简单、灵活的 API 以处理运行时权限和特殊权限请求
## 特性
- **链式 API**:便捷地添加权限并设置回调
- **自动权限管理**:处理权限请求及结果
- **支持权限说明 UI**:可在权限请求前弹出自定义提示对话框
- **兼容性强**:支持 `Activity` and `Fragment`
- **支持特殊权限**:
- `SYSTEM_ALERT_WINDOW`
- `WRITE_SETTINGS`
- `MANAGE_EXTERNAL_STORAGE`
- `REQUEST_INSTALL_PACKAGES`
## 快速开始
### 申请权限
```java
PermissionRequest.with(activity)
.addPermissions(Manifest.permission.CAMERA)
.onResult((success, granted, denied, deniedForever) -> {
if (success) {
Toast.makeText(context, "相机权限授予成功", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context, "相机权限请求失败", Toast.LENGTH_SHORT).show();
}
})
.request();
```
### 使用权限说明 UI(PermissionRationale)
如果需要在请求权限前向用户解释权限用途,可以使用 `PermissionRationale`:
```java
PermissionRequest.with(fragment)
.addPermissions(Manifest.permission.ACCESS_FINE_LOCATION)
.onResult(new PermissionRationale() {
@Override
public void showRationaleUI(@NonNull Context context, @NonNull PermissionRationaleHandler handler) {
new AlertDialog.Builder(context)
.setMessage("需要位置权限以提供更好的服务")
.setNegativeButton("拒绝", (dialog, which) -> handler.onDenied())
.setPositiveButton("允许", (dialog, which) -> handler.onAccepted())
.show();
}
@Override
public void onResult(boolean success, @NonNull List granted, @NonNull List denied, @NonNull List deniedForever) {
if (success) {
Toast.makeText(context, "位置权限授予成功", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context, "位置权限请求失败", Toast.LENGTH_SHORT).show();
}
}
})
.request();
```
## Download
在 `build.gradle` 中添加:
```gradle
dependencies {
implementation 'com.github.xenonbyte:permify:1.0.1'
}
```
## License
Copyright [2025] [xubo]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.