An open API service indexing awesome lists of open source software.

https://github.com/vinodbaste/permission_handler

On most operating systems, permissions aren't just granted to apps at install time. Rather, developers have to ask the user for permissions while the app is running. This plugin provides a API to request permissions and check their status.
https://github.com/vinodbaste/permission_handler

android android-permissions googledevelopers jitpack-library library permissions permissions-android runtime-permissions

Last synced: about 2 months ago
JSON representation

On most operating systems, permissions aren't just granted to apps at install time. Rather, developers have to ask the user for permissions while the app is running. This plugin provides a API to request permissions and check their status.

Awesome Lists containing this project

README

        

# permission_handler
On most operating systems, permissions aren't just granted to apps at install time. Rather, developers have to ask the user for permissions while the app is running.

This plugin provides a API to request permissions and check their status. You can also open the device's app settings so users can grant a permission.
and you can show a rationale for requesting a permission.

[![API](https://img.shields.io/badge/API-26%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=26)
[![GitHub tag](https://img.shields.io/github/tag/vinodbaste/image-compressor?include_prereleases=&sort=semver&color=blue)](https://github.com/vinodbaste/image-compressor/releases/)
[![License](https://img.shields.io/badge/License-Apache_2.0-blue)](#license)
[![News - Android Weekly](https://img.shields.io/badge/News-Android_Weekly-d36f21)](https://androidweekly.net/issues/issue-326)
[![Story - Medium](https://img.shields.io/badge/Story-Medium-2ea44f)](https://medium.com/codex/image-compressor-13dbfd0445a3)
[![GitHub - VinodBaste](https://img.shields.io/badge/GitHub-VinodBaste-4664c6)](https://github.com/vinodbaste/permission_handler)

# How to implement
To get a Git project into your build:
## Gradle
` Step 1:` Add it in your **root build.gradle** at the end of repositories:
```java
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
```

`Step 2:` Add the dependency in your **project build.gradle**
```java
dependencies {
implementation 'com.github.vinodbaste:permission_handler:1.0.0'
}
```

# Usage:
------

First declare your permissions in the manifest file.
Example:

```xml

```

## Single permission
Pass the permission you want to request.
```java
PermissionsHandler.requestPermission(this, Manifest.permission.CALL_PHONE, null, new PermissionHandler() {
@Override
public void onPermissionGranted() {
Toast.makeText(MainActivity.this, "Phone granted.", Toast.LENGTH_SHORT).show();
}
});
```

## Multiple permissions
pass multiple requests in a list
```java
String[] permissions = {Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE};
PermissionsHandler.requestPermission(this,permissions, null, new PermissionHandler() {
@Override
public void onPermissionGranted() {
Toast.makeText(MainActivity.this, "Permissions granted.", Toast.LENGTH_SHORT).show();
}
});
```

## override methods
**onPermissionGranted:**
This override method is called after all the permissions are granted by the user.
```java
public void onPermissionGranted(){
Toast.makeText(MainActivity.this,"Permissions granted.",Toast.LENGTH_SHORT).show();
}
```

**onPermissionDenied:**
This override method is called when any of the permission is denied by the user.
```java
@Override
public void onPermissionDenied(Context context, ArrayList deniedPermissions) {
Toast.makeText(MainActivity.this, "Location denied.", Toast.LENGTH_SHORT).show();
}
```

**onPermissionDeniedOnce:**
This override method is called when any of the permission is denied by the user once or on the first time of the permisssion promt window is displayed.
```java
@Override
public void onPermissionDeniedOnce(Context context, ArrayList justBlockedList, ArrayList deniedPermissions) {
super.onPermissionDeniedOnce(context, justBlockedList, deniedPermissions);

Log.e("onJustPermissions1", justBlockedList.toString());
Log.e("onJustPermissions2", deniedPermissions.toString());
}
```

**onPermissionNeverAskAgain:**
This override method is called when any of the permission is denied perminentaly by the user.
```java
@Override
public boolean onPermissionNeverAskAgain(Context context, ArrayList blockedList) {
return super.onPermissionNeverAskAgain(context, blockedList);
}
```
# Note
```
On permanent deny of any permission requested, navigating to application settings to enable the permanent denied permission promt is enabled by default.
```

## Customized permissions request
you can customize the permission request by using `options`.
* **rationale:** short message for why the permission is needed.
* **setRationaleDialogTitle:** title for rational dialog.
* **setSettingsDialogTitle:** title for settings dialog.
```java
String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION};
String rationale = "Please provide location permission so that you can ...";
PermissionsHandler.Options options = new PermissionsHandler.Options()
.setRationaleDialogTitle("Info")
.setSettingsDialogTitle("Warning");

PermissionsHandler.requestPermission(this, permissions, rationale, options, new PermissionHandler() {
@Override
public void onPermissionGranted() {
Toast.makeText(MainActivity.this, "Location granted.", Toast.LENGTH_SHORT).show();
}

@Override
public void onPermissionDenied(Context context, ArrayList deniedPermissions) {
Toast.makeText(MainActivity.this, "Location denied.", Toast.LENGTH_SHORT).show();
}
});

```

**If you find this library useful, please consider starring this repository from the top of this page.**
[![](https://i.imgur.com/oSLuE0e.png)](#)

# Support my work
Buy Me A Coffee

# License
```
Copyright [2022] [Vinod Baste]

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.
```