Coder Social home page Coder Social logo

permissionhelper-1's Introduction

PermissionHelper - minSdkVersion 15

How do I add PermissionHelper to my project?

Add it in your root build.gradle at the end of repositories:

allprojects {
		repositories {
			...
			maven { url "https://jitpack.io" }
		}
}

And in your module gradle build file:

dependencies {
		compile 'com.github.firetrap:permissionHelper:1.0.1'
	}

How do I use PermissionHelper?

Simple use cases will look something like this:

Manifest:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Imports:

import android.Manifest;
private PermissionHelper.PermissionBuilder permissionRequest;
private static final int REQUEST_STORAGE_CONTACTS = 2;

	View.OnClickListener onPermissionRequestClick = new View.OnClickListener() {
		@Override
		public void onClick(View v) {


			permissionRequest = PermissionHelper.with(YOUR_FRAGMENT_OR_ACTIVITY)
					.build(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.WRITE_CONTACTS)
					.onPermissionsDenied(onDenyAction)
					.onPermissionsGranted(onGrantAction)
					.request(REQUEST_STORAGE_CONTACTS);

		}
	};

	private OnDenyAction onDenyAction = new OnDenyAction() {
		@Override
		public void call(int requestCode, boolean shouldShowRequestPermissionRationale) {

			// Should we show an explanation?
			if (shouldShowRequestPermissionRationale) {

				permissionRequest.showRational(R.string.rationale_title, R.string.rationale_description, R.style.DialogTheme);
			}
		}
	};

	private OnGrantAction onGrantAction = new OnGrantAction() {
		@Override
		public void call(int requestCode) {
			//do something
		}
	};

	@Override
	public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
		permissionRequest.onRequestPermissionsResult(requestCode, permissions, grantResults);

		super.onRequestPermissionsResult(requestCode, permissions, grantResults);
	}

Extras:

You can create a dialog theme to show the rational dialog (If you want to use the system default pass null), for this you need to create a "DialogTheme":

 <style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
        <!--buttons color-->
        <item name="colorAccent">@color/colorPrimary</item>
        <!--title and message color-->
        <item name="android:textColorPrimary">@color/title_text_color</item>
        <!--dialog background-->
        <item name="android:windowBackground">@drawable/dialog_background</item>
    </style>

permissionhelper-1's People

Contributors

firetrap avatar

Watchers

James Cloos 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.