Giter Site home page Giter Site logo

android-permission-handler's Introduction

android-permission-handler

A permission helper systemizing runtime permission handling on Android devices following permission guidelines

Distribution and setup

We currently only offer aar files that can be imported. Online aar is planned but not yet available. A simple way to use the aar file is:

  1. introduce a new permissionhandler module by importing via Android Studio.
  2. add implementation project(':permissionhandler') in the build.gradle dependencies of your apps.

Usage

By "Following permission guidelines" we mean that PermissionHandler can help you organize permission request gracefully and in the meanwhile reach the responsive requirement.

For example, we show snackbars that educates user why you are asking for a permission after they have rejected the permission or they have checked "Never ask again". There is also some handling to make your app able to continue after user have granted the permission with opening your app setting page via snackbar.

Using the library

  1. Identify the actions. An action is a sequential block of code that will be executed if permission is granted / not granted. Each action requires and is mapped to a permission. For actions requiring multiple permissions, see Restrictions / Implementation. For each action, we need one actionId declared. This actionId is how we distinguish each action and is also the requestcode we will be passing to the system.
  2. Create an instance of PermissionHandler and implement interfaces in PermissionHandle that maps action and permissions. doActionDirect(), doActionGranted() and doActionSetting() are where you'd like to put your action logics. You would like to move your earlier implementations to these functions by each actionId. doActionNoPermission is the cleanup you'd like to do when the permission is not granted. makeAskAgainSnackBar() returns the snackbar that is used when user have denied or even decided to "Don't ask again" your permission requests. For simple usage we provide a Util function PermissionHandler.makeAskAgainSnackBar(). In requestPermissions() one should map the id to the permission request. For getDoNotAskAgainDialogString(), see Restrictions / Implementation.
  3. Hook specific PermissionHandler methods in corresponding lifecycle callbacks in your Activity/Fragment. These methods are onRequestPermissionsResult(), onRestoreInstanceState(), onSaveInstanceState(), and onActivityResult(). They should be hooked to the corresponding activity counterparts with the same name. When using a Fragment, one can hook onRestoreInstanceState() to onViewStateRestored()
  4. Now that all actual implementations are in the three doAction() functions, replace your original action implementations with permissionHandler.tryAction() this will automatically delegate to the correct doAction() function call.
  5. See here for an concise but thorugh example of how one can migrate to use PermissionHandler.

Restrictions / Implementation

  • We do not support actions that requires multiple permissions (yet). But we'll be happy to know if there are needs for this feature.
  • We block permission requests during the showing of snackBar.
  • If the process is killed after user enters setting, we cannot resume the action the user was trying to do before even if the user have granted the permission.
  • We uses the sharedpreference to store the permission usage.
  • getDoNotAskAgainDialogString() is currently unused but we might re-introduce them so they're currently kept in the source code.

android-permission-handler's People

Contributors

hsiangyu69 avatar kartikgits avatar mozilla-github-standards avatar mtwtm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-permission-handler's Issues

CODE_OF_CONDUCT.md file missing

As of January 1 2019, Mozilla requires that all GitHub projects include this CODE_OF_CONDUCT.md file in the project root. The file has two parts:

  1. Required Text - All text under the headings Community Participation Guidelines and How to Report, are required, and should not be altered.
  2. Optional Text - The Project Specific Etiquette heading provides a space to speak more specifically about ways people can work effectively and inclusively together. Some examples of those can be found on the Firefox Debugger project, and Common Voice. (The optional part is commented out in the raw template file, and will not be visible until you modify and uncomment that part.)

If you have any questions about this file, or Code of Conduct policies and procedures, please see Mozilla-GitHub-Standards or email [email protected].

(Message COC001)

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.