• Stars
    star
    361
  • Rank 117,957 (Top 3 %)
  • Language
    Java
  • License
    MIT License
  • Created about 8 years ago
  • Updated about 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simplifying Android Permissions

Permissify - Simplifying Android Permissions

Permissify is an Android library that makes requesting permissions at runtime much easier.

Android Marshmallow added a new functionality to let users grant permissions when running an app instead of granting them all when installing it. This approach gives the user more control but requires developers to add lots of boilerplate code to support it.

Overview

  • Tested in production - over 1000 000 installs in the Holidaycheck app
  • Handles showing Rationale & Permission denied dialogs
  • Consistent API across android versions
  • Perfectly fine with configuration changes
  • API for activity and fragment
  • Works great without hacking android
  • No memory leaks guaranteed
  • Supports Android 15+

Screenshots

Demo screenshot

Add it to your project

Include the library in your build.gradle

dependencies{
    compile 'com.holidaycheck:permissify:1.0.0'
}

or to your pom.xml if you are using Maven

<dependency>
    <groupId>com.holidaycheck</groupId>
    <artifactId>permissify</artifactId>
    <version>1.0.0</version>
    <type>aar</type>
</dependency>

Configuration

To start using the library you need to extend your activity from PermissifyActivity and configure library in your custom android.app.Application.

Minimum configuration to run is presented below. You basically need to provide translations for every Permission group that is used in your app.

public class Application extends android.app.Application {

    @Override
    public void onCreate() {
        super.onCreate();

        PermissifyConfig permissifyConfig = new PermissifyConfig.Builder()
            .withDefaultTextForPermissions(new HashMap<String, DialogText>() {{
                 put(Manifest.permission_group.LOCATION, new DialogText(R.string.location_rationale, R.string.location_deny_dialog));
                 put(Manifest.permission_group.CAMERA, new DialogText(R.string.camera_rationale, R.string.camera_deny_dialog));
                }})
              .build();

        PermissifyConfig.initDefault(permissifyConfig);
    }
}

Full configuration looks like this, but mostly you will use minimum config. You can customize default options for every permission call, and dialogs appearance. See javadoc for more details.

PermissifyConfig permissifyConfig = new PermissifyConfig.Builder()
    .withDefaultPermissionCallOptions(
        new PermissionCallOptions.Builder()
            .withDefaultDenyDialog(true)
            .withDefaultRationaleDialog(true)
            .withDefaultRationaleDialog(R.string.default_rationale_dialog_text)
            .withDenyDialogMsg(R.string.default_deny_dialog_text)
            .withRationaleEnabled(true)
            .build()
    )
    .withDefaultTextForPermissions(new HashMap<String, DialogText>() {{
        put(Manifest.permission_group.LOCATION, new DialogText(R.string.location_rationale, R.string.location_deny_dialog));
        put(Manifest.permission_group.CAMERA, new DialogText(R.string.camera_rationale, R.string.camera_deny_dialog));
    }})
    .withPermissionTextFallback(new DialogText(R.string.fallback_rationale_dialog_text, R.string.fallback_deny_dialog_text))
    .withDialogRationaleDialogFactory(new PermissifyConfig.AlertDialogFactory() {
        @Override
        public AlertDialog createDialog(Context context, String dialogMsg, DialogInterface.OnClickListener onClickListener) {
            return new CustomRationaleDialog(context, dialogMsg, onClickListener);
        }
    })
    .withDenyDialogFactory(new PermissifyConfig.AlertDialogFactory() {
        @Override
        public AlertDialog createDialog(Context context, String dialogMsg, DialogInterface.OnClickListener onClickListener) {
            return new CustomDenyDialog(context, dialogMsg, onClickListener);
        }
    })
    .build();

PermissifyConfig.initDefault(permissifyConfig);

Usage

To request specific permission you need make a call to PermissifyManager. Every call is associated with your unique RequestId.

getPermissifyManager().callWithPermission(this, LOCATION_PERMISSION_REQUEST_ID, android.Manifest.permission.ACCESS_FINE_LOCATION);

the result and the current permission status is provided via

@Override
public void onCallWithPermissionResult(int callId, PermissifyManager.CallRequestStatus status) {
    if (callId == LOCATION_PERMISSION_REQUEST_ID) {
        switch (status) {
            case PERMISSION_GRANTED:
                getUserLocation();
            break
            case PERMISSION_DENIED_ONCE:
            //do some custom logic
            break;
            case PERMISSION_DENIED_FOREVER:
            //do some custom logic
            case SHOW_PERMISSION_RATIONALE:
            //do some custom logic
        }
    }
}

If you want to request permission from a fragment make sure it implements PermissifyManager.Callback

There are two types of dialogs:

  • Rationale dialog - is shown in situations where the user might need an explanation why the app needs this permission
  • Deny dialog - is shown when the user permanently denied requested permission

There are number of options that you can change when requesting for permission using additional parameter:

getPermissifyManager().callWithPermission(this, LOCATION_PERMISSION_REQUEST_ID, android.Manifest.permission.ACCESS_FINE_LOCATION,
            new PermissionCallOptions.Builder()
                .withDefaultDenyDialog(false)
                .withRationaleEnabled(false)
                .build());

Current limitations

  • Multiple permission request at once is not currently supported (will be added soon)

Do you want to contribute?

Feel free to add any cool and useful feature to the library.

License

The MIT License (MIT)

Copyright (c) 2016 HolidayCheck

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

react-google-tag-manager

This repository contains a react based implementation for Google's Tag Manager snippet.
JavaScript
192
star
2

nix-remote-builder

Easy way to set up a linux remote builder in docker
Shell
28
star
3

RecyclerViewInjectorAdapter

RecyclerView.Adapter on steroids
Java
15
star
4

nix-venient

A collection of convenient commands for working with nix/nixpkgs
Shell
12
star
5

lean-jira-export

Allows to export jira issues based on configurable JQL including lean metrics data such as lead-time & cycle-time
Java
10
star
6

gemini-ci-gui

CI GUI for Gemini
JavaScript
10
star
7

easy-akka-http

Additional things we use to make life with akka-http easier
Scala
8
star
8

healthcheck-ping

express health check middleware
JavaScript
8
star
9

auth0-bundler

Bundle rules, scripts and hooks to deploy them to Auth0.
JavaScript
8
star
10

amqp-akka-streams

A library that allow you to leverage Akka Streams while reading or writing messages to AMQP broker.
Scala
8
star
11

tech-blog

HolidayCheckers blogging about things they care about
HTML
8
star
12

marathon-maven-plugin

Maven plugin for interacting with Marathon
Java
6
star
13

frontend-assignment

Homework task for FrontEnd recruiting process
5
star
14

mesos-in-the-box

Apache Mesos + Marathon + Haproxy ran on single host as Docker containers.
Shell
5
star
15

react-ssi-fragment

TypeScript
4
star
16

gemini-json-reporter

Gemini plugin that generates a single JSON report file.
JavaScript
4
star
17

sanitize-marathon-app-id

🚮 Sanitize marathon app ids.
JavaScript
4
star
18

eslint-config-holidaycheck

ESLint configuration from holidaycheck
JavaScript
3
star
19

gcp-quota-exporter

Prometheus exporter for Google Cloud Platform resource quota
Python
3
star
20

car_pooling_bot

this app is built to make Business Travels Carpooling much easier, it's built with Interactivity user interface
JavaScript
2
star
21

morning-katas

This repo contains the schedule, instructions and all kinds of links for the #morningKata as we do them in HolidayCheck.
2
star
22

apprenticeship

The HolidayCheck Apprenticeship Page
Nix
2
star
23

redux-pre-thunk

Pre thunk middleware for unit testing
JavaScript
2
star
24

coding-katas

JavaScript
1
star
25

koa-prevent-caching

Set appropriate response headers to prevent caching.
JavaScript
1
star
26

delta-detect-links

Detect links in a delta object.
JavaScript
1
star
27

google-analytics-persister

Read data from google analytics and persist them in Time Series Database (InfluxDB)
JavaScript
1
star
28

push-docker-image

⬆️Push docker image .tar.gz files to a docker registry.
JavaScript
1
star
29

react-meetup-intro

Into talk for the ReactJS Munich Meetup 22.02.2016
JavaScript
1
star
30

issue-prioritizer

Set priority of github issue based on potential, weight and effort metrics
JavaScript
1
star
31

hc-carousel-component

A reusable carousel webcomponent. Tries not to be opinionated, tries to be just like a (new) HTML element.
JavaScript
1
star
32

liam

Simple tool for running tasks against your GitHub repository and/or other services.
JavaScript
1
star
33

hc-event-component

A web-component containing all the things that (we think) represent an event.
HTML
1
star