百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
P

permiso

> 编程语言
开源

一个 Android 库,可让处理运行时权限变得更加简单。

188 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

一个 Android 库,可让处理运行时权限变得更加简单。

Permiso

Permiso is an Android library that makes requesting runtime permissions a whole lot easier.

Have you seen the docs for how to request runtime permissions? Who wants to do that every time you request a permission? Let's clean this up!

Features

  • Localizes permission requests so you can handle everything using a simple callback mechanism.
  • Can easily make permission requests outside of the context of an Activity.
  • Simplifies showing the user your rationale for requesting a permission.
  • Can request multiple permissions at once.
  • Merges simultaneous requests for the same permission into a single request.

Usage

If your Activity subclasses PermisoActivity, requesting a permission is as simple as:

java
Permiso.getInstance().requestPermissions(new Permiso.IOnPermissionResult() {
    @Override
    public void onPermissionResult(Permiso.ResultSet resultSet) {
        if (resultSet.areAllPermissionsGranted()) {
            // Permission granted!
        } else {
            // Permission denied.
        }
    }

    @Override
    public void onRationaleRequested(Permiso.IOnRationaleProvided callback, String... permissions) {
        Permiso.getInstance().showRationaleInDialog("Title", "Message", null, callback);
    }
}, Manifest.permission.READ_EXTERNAL_STORAGE);

Requesting Multiple Permissions

Requesting multiple permissions at once is just as easy.

…

Gradle

Latest Stable Version

java
dependencies {
    compile 'com.greysonparrelli.permiso:permiso:0.3.0'
}

Latest Dev Version

java
// In your top-level build.gradle
repositories {
    maven { url "https://www.jitpack.io" }
}
// In your module's build.gradle
dependencies {
    compile 'com.github.greysonp:permiso:master-SNAPSHOT'
}

FAQ

I don't want my Activity to subclass PermisoActivity. Do I have to?

Of course not! Permiso requires very little boilerplate, and therefore PermisoActivity does very little. If you don't want to subclass PermisoActivity, all you have to do is make sure you do the two following things:

  • In onCreate() and onResume(), invoke Permiso.getInstance().setActivity(this).
  • Forward the results of Activity.onRequestPermissionsResult() to Permiso.getInstance().onRequestPermissionResult().

Here's an example:

java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Permiso.getInstance().setActivity(this);
}

@Override
protected void onResume() {
    super.onResume();
    Permiso.getInstance().setActivity(this);
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    Permiso.getInstance().onRequestPermissionResult(requestCode, permissions, grantResults);
}

I don't want to show any rationale for my permissions.

According to the Android Guidelines you probably should, but there's no hard requirement. If you don't want to show a rationale, simply invoke the callback and do nothing else:

java
@Override
public void onRationaleRequested(Permiso.IOnRationaleProvided callback, String... permissions) {
    callback.onRationaleProvided();
}

I want to do some complicated logic with the results of my permission request, but the ResultSet doesn't let me.

Fear not! The ResultSet object has a method called toMap(), which will give you back a mapping of permissions -> Permiso.Result that you can iterate over to your heart's content.

What do you mean when you say that Permiso merges simultaneous requests for the same permission into a single request?

If you request the same permission in two places simultaneously, Permiso will automatically merge them into one request. You might think this is a rare scenario, but before you know it, you have master and detail fragments that both need access to the user's contacts, and now you have to manage your permissions so their simultaneous requests don't cause two separate pop-ups! Don't worry, Permiso handles this for you.

I request a permission but nothing happens? What's up?

Did you make sure to declare your permissions in your AndroidManifest.xml? If you don't, permission requests fail silently. That's an Android thing - not much Permiso can do there.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Java

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言