<commit_before>Permiso [![Build Status](https://travis-ci.org/greysonp/permiso.svg?branch=master)](https://travis-ci.org/greysonp/permiso) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Permiso-green.svg?style=true)](https://android-arsenal.com/details/1/2818)
=======

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

Have you seen the [docs](http://developer.android.com/training/permissions/requesting.html) 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.

```java
Permiso.getInstance().requestPermissions(new Permiso.IOnPermissionResult() {
    @Override
    public void onPermissionResult(Permiso.ResultSet resultSet) {
        if (resultSet.isPermissionGranted(Manifest.permission.READ_CONTACTS)) {
            // Contact permission granted!
        }
        if (resultSet.isPermissionGranted(Manifest.permission.READ_CALENDAR)) {
            // Calendar permission granted!
        }
    }

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

Gradle
------
```java
dependencies {
    compile 'com.greysonparrelli.permiso:permiso:0.1.2'
}
```

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);
}
<commit_msg>Updated version in README.<commit_after>Permiso [![Build Status](https://travis-ci.org/greysonp/permiso.svg?branch=master)](https://travis-ci.org/greysonp/permiso) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Permiso-green.svg?style=true)](https://android-arsenal.com/details/1/2818)
=======

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

Have you seen the [docs](http://developer.android.com/training/permissions/requesting.html) 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.

```java
Permiso.getInstance().requestPermissions(new Permiso.IOnPermissionResult() {
    @Override
    public void onPermissionResult(Permiso.ResultSet resultSet) {
        if (resultSet.isPermissionGranted(Manifest.permission.READ_CONTACTS)) {
            // Contact permission granted!
        }
        if (resultSet.isPermissionGranted(Manifest.permission.READ_CALENDAR)) {
            // Calendar permission granted!
        }
    }

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

Gradle
------
```java
dependencies {
    compile 'com.greysonparrelli.permiso:permiso:0.1.3'
}
```

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);
}

{'fraction_non_alphanumeric': 0.11887273272372957, 'fraction_numerical': 0.00299805126667666, 'mean_word_length': 4.350441058540497, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2780325', 'n_tokens_mistral': 1861, 'n_tokens_neox': 1806, 'n_words': 519}