Git Product home page Git Product logo

app-runtime-permissions-android's Introduction

Runtime Permission Library (Example)

A simple library that will remove all the boilerplate code and speed up your work with new Runtime Permissions introduced in Android M.

What are Runtime Permissions?

Google docs is here. Unlike the traditional way of asking permission Android M increased its security by enforcing apps to ask permissions on the fly as and when the user requests for a feature that requires those permissions. These permissions can also be revoked by the user at any time.

How to integrate into your app?

Integrating the library into you app is extremely easy. A few changes in the build gradle and your all ready to user Runtime permissions library. Make the following changes to build.gradle inside you app.

.....
dependencies {
  ...
  compile 'com.mukesh:permissions:1.0.3'
}

How to use the library?

Okay seems like you integrated the library in your project but how do you use it? Well its really easy just follow the steps below.

 AppPermissions runtimePermission = new AppPermissions(Activity currentActivity);

This will create an object of the Runtime Permission class for you. Make sure it's an object of com.mukesh.permissions.AppPermissions To check if the app has a specific permission you can call runtimePermission.hasPermission(String permission); or if you want to check whether the app has multiple permission you can call runtimePermission.hasPermission(String[] permissions).

or like how google requests for multiple permissions

You can request for a permission by calling runtimePermission.requestPermission(String permission, int requestCode) or request multiple permissions by calling runtimePermission.requestPermission(String[] permissions, int requestCode). However you will need to override a method on your activity inorder to wait for a callback from the library. Just add this to you activity.

@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    if (requestCode == mRequestCode) { //The request code you passed along with the request.
    //grantResults holds a list of all the results for the permissions requested.
      for (int grantResult : grantResults) {
        if (grantResult == PackageManager.PERMISSION_DENIED) {
          Log.d("PermissionResult=>", "Denied");
          return;
        }
      }
      Log.d("PermissionResult=>", "All Permissions Granted");
    }
  }

That's pretty much it and your all wrapped up.

app-runtime-permissions-android's People

Watchers

Pham Trung Phuong 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.