GithubHelp home page GithubHelp logo

flagbeat / gramit Goto Github PK

View Code? Open in Web Editor NEW
7.0 3.0 0.0 7.98 MB

A library to simplify permission handling in Android

android runtime-permissions permission-android android-permissions library android-library dialog flagbeat permission

gramit's Introduction

Gramit

Download

A library to simplify runtime permission handling in Android

Demo Screens

Features

  • Out of the box permission handling with less boilerplate code.
  • Configurable permission dialogue to explain why you need permissions.
  • Permission dialogue shows carousel having cards with thumbnail and message related to a particular permission.
  • Enable IsMendatory flag to force the user for granting a mendatory permission.
  • In case of mendatory permission, even if a user chooses "Never ask again", the library shows a blocking dialogue that takes the user to the Phone settings > Permission section.
  • Returns accepted, denied and declined (Never ask again) permissions and a grant code.

Installation

Gradle

Add this Gradle dependency to your app/build.gradle file

implementation "com.flagbeat.gramit:gramit:1.1.7"

Maven

<dependency>
	<groupId>com.flagbeat.gramit</groupId>
	<artifactId>gramit</artifactId>
	<version>1.1.7</version>
	<type>pom</type>
</dependency>

Usage

  1. Create a list of the required permissions
List<Permission> permissions = new ArrayList<>();
// Read Log Permission
permissions.add(
    Permission.builder()
              .permissionName(Manifest.permission.READ_CALL_LOG)
              .popupMessage("Add your call rationale here")
              .isMandatory(false)
              .popupThumbnailResourceId(R.drawable.default_permission_icon)
              .build()
);
// Read Contact Permission
permissions.add(
    Permission.builder()
              .permissionName(Manifest.permission.READ_CONTACTS)
              .popupMessage("Add your contacts rationale here")
              .isMandatory(true)
              .popupThumbnailRemoteUrl("https://flagbeat.com/img/flagbeat_loader.png")
              .build()
);
  1. Pass the permission list to the Gramit library
Gramit.builder()
      .context(this)
      .permissions(permissions)
      .showContextualMessage(true)
      .openSettingText("Go to App permissions and enable all the required permissions.")
      .popupOkButtonText("Got it")
      .build();
  1. (Optional) In the activity, you will get the grant status callback in onActivityResult method. Received intent contains grant code, lists of granted permissions, denied permissions and declined permissions (Never ask again permissions). Grant Code:
    1. Gramit.FULL_PERMISSION_GRANT
    2. Gramit.PARTIAL_PERMISSION_GRANT
    3. Gramit.NO_PERMISSION_GRANT
    @Override
    public void onActivityResult(int requestCode, int resultCode,
                                 Intent data)
    {
        if (RESULT_OK == resultCode)
        {
            switch (requestCode)
            {
                case Gramit.GRAMIT_REQUEST_CODE:
                    handleGramitResponse(data);
                    break;
            }
        }
    }
    
    private void handleGramitResponse(Intent data)
    {
        Log.i("Grant Code ",
              String.valueOf(data.getIntExtra(Gramit.GRANT_CODE, 0)));
        Log.i("GRANTED_PERMISSIONS ",
              Arrays.toString(data.getStringArrayExtra(Gramit.GRANTED_PERMISSIONS)));
        Log.i("DENIED_PERMISSIONS ",
              Arrays.toString(data.getStringArrayExtra(Gramit.DENIED_PERMISSIONS)));
        Log.i("DECLINED_PERMISSIONS ",
              Arrays.toString(data.getStringArrayExtra(Gramit.DECLINED_PERMISSIONS)));
    }

That's it!

Compatibility

minSdkVersion 16

Progaurd

Debugging

If you are not getting a permission specific card in the permission dialogue carousel, then check below:

  • Check if you have declared the permission in the Manifest file.
  • Check if you have added the permission in the permission list before submitting it to Gramit library.
  • Raise a bug here otherwise as per this template.

Who's using it

Developed by

Used libraries

  • Picasso: It has been used to load remote url of thumbnails in permission dialogue.
  • Lombok: It has been used for getter, setter and builder pattern but don't worry it is a compile-time only library, won't make your app 'heavier'.

License

Copyright 2019 Sumit Saurabh

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.

gramit's People

Contributors

flagbeat avatar sumit-saurabh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.