Android Library to help you with your runtime Permissions.

Overview

PermissionHelper

Android Library to help you with your runtime Permissions.

Demo

Android M Watch it in action.
Pre M Watch it in action. Nexus 6 (M)

Nexus 6

Nexus 7 (L)

ScreenShot

Nexus 10 (L)

ScreenShot

Installation

Gradle

    compile 'com.github.k0shk0sh:PermissionHelper:1.1.0'

Maven

<dependency>
  <groupId>com.github.k0shk0sh</groupId>
  <artifactId>PermissionHelper</artifactId>
  <version>1.1.0</version>
  <type>aar</type>
</dependency>

Usage

Ask Permissions in Style

Have you wondered what will give you a higher chance of letting the user accepts your permission?

The answer is simple: (Educating UI) that explains why you need to use that particular permission.

  • All you need to do is extending BasePermissionActivity.

    • By extending BasePermissionActivity you'll have control over (Features):
      • Permissions that being asked and their Explanation if its needed.
      • Each Screen Background color (DarkPrimaryColor of that background will be generated automatically).
      • Each Screen Image Resource.
      • Each Screen Title & Message.
      • Each Screen Title & Message Text Color.
      • Each Screen Title & Message Text Size.
      • Each Screen Text & Message FontType, yes you heard me right, each Screen can have their own FontType.
      • Each Screen Next, Previous & Request Buttons Icon Resources.
      • Your Own Theme.
      • Your Own Implementation of ViewPager.PageTransformer or use the default one.
      • You can defined for instance that a particular permission can't be skipped until the Explanation Dialog is showed.(follow example code below to know how).
      • BasePermissionActivity support Portrait & Landscape modes for both Mobile Phones & Tablets (as showing in above images).
      • SYSTEM_ALERT_WINDOW Permission is being automatically handled if you ever pass it along other permissions ;) .
  • And Finally Let The Library Do The Job For You. in Style.

Notice

You still can use the library to explain why you used the permission in your app, the library will never try ask the permission if Android is smaller than M, it will just do like any Intro library does. as you can see in Nexus 7 & Nexus 10 screens running Android L, request button is hidden ;).

For Better Understanding, please have a look at the example code at SamplePagerActivity

Take Control.

Your Activity/Fragment/Presenter should implement OnPermissionCallback which in return will give you access to

    void onPermissionGranted(String[] permissionName);

    void onPermissionDeclined(String[] permissionName);

    void onPermissionPreGranted(String permissionsName);

    void onPermissionNeedExplanation(String permissionName);  
    
    void onPermissionReallyDeclined(String permissionName);//user has ticked don't show again and deny the permission

    void onNoPermissionNeeded(); // fallback to api < M

to request a permission all you have to do is:

  • Activity
permissionHelper
     .setForceAccepting(false)// true if you had like force reshowing the permission dialog on Deny (not recommended)
     .request(isSingle ? SINGLE_PERMISSION : MULTIPLE_PERMISSIONS);
  • Fragment
permissionFragmentHelper
     .setForceAccepting(false)// true if you had like force reshowing the permission dialog on Deny (not recommended)
     .request(isSingle ? SINGLE_PERMISSION : MULTIPLE_PERMISSIONS);

To request a permission without ask for explanation message even if the user press decline:

permissionHelper
     .setSkipExplanation(true)// true if you don't want to show expalanation message
     .request(CAMERA_PERMISSION);


and finally in your `Activity/Fragment`
```java
onRequestPermissionsResult(....)

call

permissionHelper.onRequestPermissionsResult(....)

Extra Activity/Fragment

  • Depends on whether you using PermissionHelper or PermissionFragmentHelper you can call these methods
public static String declinedPermission(@NonNull Context/Fragment context, @NonNull String[])
public static String[] declinedPermissions(@NonNull Context/Fragment context, @NonNull String[] permissions)
public static boolean isPermissionGranted(@NonNull Context/Fragment context, @NonNull String permission)
public static boolean isPermissionDeclined(@NonNull Context/Fragment context, @NonNull String permission)
public static boolean isExplanationNeeded(@NonNull Activity/Fragment context, @NonNull String permissionName)
public static boolean permissionExists(@NonNull Context/Fragment context, @NonNull String permissionName)
public static boolean isPermissionPermanentlyDenied(@NonNull Activity/Fragment context, @NonNull String permission)
public static void openSettingsScreen(Context/Fragment context)//useful when we can't request for the permission due to user ticked don't show again.
@TargetApi(Build.VERSION_CODES.M)
public static boolean isSystemAlertGranted(@NonNull Context/Fragment context)// special case for SYSTEM_ALERT_WINDOW permission.

all of the above static methods you can still access them with PermissionHelper or PermissionFragmentHelper instance.

Why this library?

  • Its simple to use.
  • Its Unique, Customizable & read back first point.
  • You have two choices, do it your way through callbacks, or let the Library do it for you with your look & Feel.
  • Minimum API is 14, but it'll probably work in API 11 and above, just make sure you test it out.

If you're using this library drop me an email at [email protected] to include in the list.

Dependency

Android Support library v24.2.1

CirclePageIndicator by JakeWharton (integrated within the library).

Images

Images used inside the demo are by Maximilian Keppeler

Copyright Notice

Copyright (C) 2015 Kosh. Licensed under the Apache 2.0 license (see the LICENSE file).

Comments
  • Multiple permission

    Multiple permission

    Hallo,

    I want showing my Permissions like this. But my code doesn't work. It only show always the first permission of the list. Could you help me pls.

    unbenannt

    public final static String WRITE_EXTERNAL_STORAGE_PERMISSION = Manifest.permission.WRITE_EXTERNAL_STORAGE;
    public final static String ACCESS_FINE_LOCATION_PERMISSION = Manifest.permission.ACCESS_FINE_LOCATION;
    public final static String CAMERA_PERMISSION = Manifest.permission.CAMERA;
    
    public final static String[] MULTIPLE_PERMISSIONS = {WRITE_EXTERNAL_STORAGE_PERMISSION,
                ACCESS_FINE_LOCATION_PERMISSION,
                CAMERA_PERMISSION};
    
    permissionHelper.setForceAccepting(false)
                    .request(PermissionsStatesHelper.MULTIPLE_PERMISSIONS);
    
    duplicate 
    opened by drchopper 15
  • PermissionModelBuilder in ActivityMain?

    PermissionModelBuilder in ActivityMain?

    Can you post an example of how to reference an array element from SamplePagerActivity in SampleActivity? I am trying to customize the boxes, but when I call

    permissionHelper .setForceAccepting(false) .request(MULTI_PERMISSIONS);

    No customizations appear. Just the default alerts.

    help wanted question 
    opened by digitalprecision 11
  • Camera access example

    Camera access example

    Seems easy enough:

    protected void intentCamera()
    {
        permissionHelper
            .setForceAccepting(false)
            .request(MULTI_PERMISSIONS); // CAMERA and WRITE_EXTERNAL_STORAGE
    
        showCamera();
    }
    

    But doesn't work as expected, as showCamera() is called regardless of the status of the permissions. Does showCamera() go into onRequestPermissionsResult()?

    help wanted question 
    opened by digitalprecision 8
  • Multiple permissions

    Multiple permissions

    @k0shk0sh This problem still exists in Android 6.0.1. I am using v1.0.11 but still not getting expected multiple permissions.. it shows only first permission from list. and if first permission is granted then only it displays next one.. but it is not showing non granted permissions in queue.. as shown in images above by @drchopper i have tried as said in #10 this issue but dint worked for me

    opened by sgaikar1 7
  • Add a typesafe constructor for PermissionHelper

    Add a typesafe constructor for PermissionHelper

    Yet another mini-PR :) Before you had to use

    permissionHelper.request(new String[]{Manifest.permission.GET_ACCOUNTS,Manifest.permission.ACCESS_FINE_LOCATION);
    

    Now

    permissionHelper.request(Manifest.permission.GET_ACCOUNTS,Manifest.permission.ACCESS_FINE_LOCATION);
    

    I didn't remove the unsafe constructor because you can't use mine this way permissionHelper.request(isSingle ? SINGLE_PERMISSION : MULTI_PERMISSIONS);

    enhancement 
    opened by Allsimon 5
  • Displaying wrong PermissionModel

    Displaying wrong PermissionModel

    Look at the screenshot.

    You vcan see the permission is android.permission.GET_ACCOUNTS

    And the PermissionModel is for android.permission.ACCESS_FINE_LOCATION

    2016-02-18_13h03_21

    My PermissionModel is defined like this for testing

        List<PermissionModel> permissions = new ArrayList<>();
        permissions.add(PermissionModelBuilder.withContext(this)
                .withTitle("ACCESS_FINE_LOCATION")
                .withCanSkip(false)
                .withPermissionName(Manifest.permission.ACCESS_FINE_LOCATION)
                .withMessage("PermissionHelper also prevents your app getting crashed if the " +
                        "requested permission never exists in your AndroidManifest" +
                        ". Android DOES!")
                .withExplanationMessage("We need this permission to access to your location to" +
                        " find nearby restaurants and places you like!")
                        //.withFontType("my_font.ttf")
                .withLayoutColorRes(R.color.primary_color)
                .withImageResourceId(R.drawable.logo_image)
                .build());
    
        permissions.add(PermissionModelBuilder.withContext(this)
                .withTitle("GET_ACCOUNTS")
                .withCanSkip(true)
                .withPermissionName(Manifest.permission.GET_ACCOUNTS)
                .withTitle(R.string.title_get_accounts)
                .withMessage(R.string.message_get_accounts)
                .withExplanationMessage(R.string.explanation_message_get_accounts)
                        //.withFontType("my_font.ttf")
                .withLayoutColorRes(R.color.primary_color)
                .withImageResourceId(R.drawable.logo_image)
                .build());
    
        permissions.add(PermissionModelBuilder.withContext(this)
                .withTitle("READ_CONTACTS")
                .withCanSkip(true)
                .withPermissionName(Manifest.permission.READ_CONTACTS)
                .withTitle("READ_CONTACTS")
                .withMessage(R.string.message_get_accounts)
                .withExplanationMessage(R.string.explanation_message_get_accounts)
                        //.withFontType("my_font.ttf")
                .withLayoutColorRes(R.color.primary_color)
                //.withImageResourceId(R.drawable.permission_three)
                .build());
    
        permissions.add(PermissionModelBuilder.withContext(this)
                .withTitle("WRITE_CONTACTS")
                .withCanSkip(true)
                .withPermissionName(Manifest.permission.WRITE_CONTACTS)
                .withTitle("WRITE_CONTACTS")
                .withMessage(R.string.message_get_accounts)
                .withExplanationMessage(R.string.explanation_message_get_accounts)
                        //.withFontType("my_font.ttf")
                .withLayoutColorRes(R.color.primary_color)
                        //.withImageResourceId(R.drawable.permission_three)
                .build());
    
        permissions.add(PermissionModelBuilder.withContext(this)
                .withTitle("WRITE_EXTERNAL_STORAGE")
                .withCanSkip(true)
                .withTitle("WRITE_EXTERNAL_STORAGE")
                .withPermissionName(Manifest.permission.WRITE_EXTERNAL_STORAGE)
                .withMessage("PermissionHelper lets you customize all these stuff you are seeing!." +
                        " if you ever thought of anything that improves the library please" +
                        " suggest by filling up an issue in github https://github.com/k0shk0sh/PermissionHelper")
                .withExplanationMessage("We need this permission to save your captured images and videos to your SD-Card")
                        //.withFontType("my_font.ttf")
                .withLayoutColorRes(R.color.black)
                .withImageResourceId(R.drawable.logo)
                .build());
    
        permissions.add(PermissionModelBuilder.withContext(this)
                .withTitle("SYSTEM_ALERT_WINDOW")
                .withCanSkip(false) /*explanation only once will be called otherwise we will
                            run into infinite request if the user never grant the permission.*/
                .withTitle("SYSTEM_ALERT_WINDOW")
                .withPermissionName(Manifest.permission.SYSTEM_ALERT_WINDOW)
                .withMessage("PermissionHelper handles requesting SYSTEM_ALERT_WINDOW permission")
                .withExplanationMessage("We need this permission to make our videoPlayer overlay on your screen.")
                //.withFontType("my_font.ttf")
                .withLayoutColorRes(R.color.primary_color)
                .withImageResourceId(R.drawable.logo_image).build());
    
        return permissions;
    
    bug 
    opened by biovolt 3
  • Notification Access Permissions

    Notification Access Permissions

    Hey, it would be awesome if you could implement support for android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS. This is similar to the system alert window permission in that you need to go to settings to change it.

    invalid 
    opened by rammadogs 2
  • Something went wrong with release .10

    Something went wrong with release .10

    The uploaded artifacts (source and aar) have the request method in base with the == not the latest >= on the sdk check..

    Looks a bit like the wrong artifact got uploaded. the release zip is fine..

    opened by mwinters-stuff 2
  • create a new release.

    create a new release.

    Is it possable to get a new release with the change that fixes the version check on the release call?

    Just tried my app on android V24 and it failed to popup the permission because of this..

    opened by mwinters-stuff 2
  • Add a builder-style generator for PermissionModel

    Add a builder-style generator for PermissionModel

    This is a more fluent way to construct PermissionModel For example, before :

    List<PermissionModel> permissions = new ArrayList<>();
    PermissionModel model = getDefaultInstance();
    model.setCanSkip(true);
    model.setPermissionName(Manifest.permission.GET_ACCOUNTS);
    model.setTitle(this.getResources().getString(R.string.title_get_accounts));
    model.setMessage(this.getResources().getString(R.string.message_get_accounts));
    model.setExplanationMessage(this.getResources().getString(R.string.explanation_message_get_accounts));
    model.setFontType("my_font.ttf");
    model.setLayoutColorRes(this.getResources().getColor(R.color.colorPrimary));
    model.setImageResourceId(R.drawable.permission_three);
    permissions.add(model);
    

    After:

    List<PermissionModel> permissions = new ArrayList<>();
    permissions.add(PermissionModelBuilder.withContext(this)
            .withCanSkip(true)
            .withPermissionName(Manifest.permission.GET_ACCOUNTS)
            .withTitle(R.string.title_get_accounts)
            .withMessage(R.string.message_get_accounts)
            .withExplanationMessage(R.string.explanation_message_get_accounts)
            .withFontType("my_font.ttf")
            .withLayoutColorRes(R.color.colorPrimary)
            .withImageResourceId(R.drawable.permission_three)
            .build());
    
    enhancement 
    opened by Allsimon 2
  • Implementation help

    Implementation help

    PermissionsActivity.java.zip

    hey im trying to implement your pager example and apparently i didi everything right but and i click the check button a request popup show and not a permission popup mu code is attached could you help me out

    opened by blennerSilva 1
Releases(v1.1.1)
  • v1.1.1(Jul 27, 2018)

  • v1.1.0(Oct 17, 2016)

    This release has a new feature that it should've been there since version 1.0.

    • PermissionFragmentHelper which is made specially for Fragments to avoid the extra work you had to do in previous version.
    • updated support library to 24.2.1
    Source code(tar.gz)
    Source code(zip)
  • v1.0.13(Sep 4, 2016)

  • v1.0.12(Aug 28, 2016)

    Changelog

    • Deprecating accessing PermissionModel directly and encourage the usage of PermissionModelBuilder
    • Added TextSize checking to ensure that the passed size is a resource id or a plain value.
    • Added TypeFace caching to avoid recreating the TypeFace if it's already created.
    • Updated support library and build tools to version 24.0.2 .
    • Added Nullity annotations to stuff that either could be null or not null.
    Source code(tar.gz)
    Source code(zip)
  • v1.0.11(Aug 10, 2016)

  • v1.0.10(Aug 9, 2016)

    this release in points:

    • updated support library & buildtools to 24.
    • fixed imageView height in small phones where the imageView might take over the whole space.
    • renaming all layouts so no conflicts could happen with other projects.
    • added more annotations such as Nullable & NonNull to methods.
    • formatted code 👍
    Source code(tar.gz)
    Source code(zip)
  • v1.0.9(Mar 28, 2016)

    • fixed a bug where the first permission is being asked always.
    • added to return perGranted callback for System_Alert permission if it has been requested and granted previously.
    • update text size for title where it might look large.
    • code formatting and improvement.
    Source code(tar.gz)
    Source code(zip)
  • v1.0.8(Jan 12, 2016)

  • v1.0.7(Nov 19, 2015)

  • v1.0.6(Nov 18, 2015)

  • v1.0.5(Nov 18, 2015)

  • v1.0.3(Nov 16, 2015)

    • callback to know if the user ticked don't show again and declined the permission.
    • fixed a bug where you might not get onPermissionGranted.
    Source code(tar.gz)
    Source code(zip)
Owner
Kosh Sergani
I'm a Networking by education & Android developer by choice.
Kosh Sergani
andle is an Android tool help you sync dependencies, sdk or build tool version.

andle andle is an Android tool to help you sync dependencies, SDK or build tool version. Installation Simple install by pip: $ sudo pip install andle

Jintin 58 Sep 17, 2022
Cache support for any video player with help of single line

Video cache support for Android Table of Content Why AndroidVideoCache? Features Get started Recipes Disk cache limit Listen caching progress Providin

Alexey Danilov 5.1k Jan 6, 2023
Tired of manually setup test data of Kotlin data classes or POJOs? Instantiator creates Instances of any class for you so that you can focus on writing tests instead of spending time and effort to setup test data

Instantiator Tired of manually setup test data of Kotlin data classes or POJOs? Instantiator creates Instances of any class for you so that you can fo

Hannes Dorfmann 54 Dec 30, 2022
Make your IDE play Wilhelm Scream effect when you are using unsafe !! operator in Kotlin

Make your IDE play Wilhelm Scream effect when you are using unsafe !! operator in Kotlin

Mikhail Levchenko 78 Nov 15, 2022
An application for runners and cyclists. Allows you to monitor your physical activity, weight and receive reminders about workouts.

An application for runners and cyclists. Allows you to monitor your physical activity, weight and receive reminders about workouts.

Just_Amalll 3 Feb 7, 2022
Android library that manages your app's cached data with ease.

Teller Android library that makes your apps faster. Teller facilitates the downloading, saving, and reading of the cached data of your app. Keep your

Levi Bostian 14 Apr 2, 2022
SL4A brings scripting languages to Android by allowing you to edit and execute scripts and interactive interpreters directly on the Android device.

#Scripting Layer for Android (SL4A) SL4A brings scripting languages to Android by allowing you to edit and execute scripts and interactive interpreter

Damon Kohler 2.3k Dec 23, 2022
This repository contains a simple script that lets you kill gradle and kotlin daemons.

AndroidDaemonKiller This repository contains a simple script that lets you kill gradle and kotlin daemons. After updating gradle or kotlin or checking

Paul Woitaschek 25 Dec 3, 2022
Use your old Android device as an OctoPrint server.

Use your old Android device as an OctoPrint server.

Feelfree (Filip) 1k Dec 31, 2022
The BitbucketWatcher is a helpful tool to keep up to date with updates on your repo.

The BitbucketWatcher is a helpful tool to keep up to date with updates on your repo. The Watcher tracks new PullRequests, status changes on code reviews, merged branches and forgotten branches.

null 4 Jan 10, 2022
A Utility to Add all of your installed steam games to the Start Launcher for Windows

Steam Start Launcher The Steam Start launcher is a small tool that will scan your computer for isntalled steam games and create a shortcut for each ga

null 1 Dec 1, 2021
Throw your friends out!

ThrowIt-Mirai 丢人插件 简单高效的 “丢人” 插件 把你的群友丢出去吧 使用方法: 将插件置于plugin目录下, 并安装chat-command插件 使用插件需要权限 pers.moe.throwit-mirai:command.丢 perm permit m* pers.moe.t

Moe 25 Oct 24, 2022
Starter-Android-Library - Starter Android Library is an Android Project with Modular Architecture.

Starter-Android-Library - Starter Android Library is an Android Project with Modular Architecture.

OpenBytes 1 Feb 18, 2022
****. Use the native and support library variants instead - https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml.html. An android library that makes it easy to add custom fonts to edittexts and textviews

Add to your project Add this line to your dependencies in build.gradle compile 'in.workarounds.typography:typography:0.0.8' Using the views There are

Workarounds 43 Nov 6, 2021
ZXing ("Zebra Crossing") barcode scanning library for Java, Android

Project in Maintenance Mode Only The project is in maintenance mode, meaning, changes are driven by contributed patches. Only bug fixes and minor enha

ZXing Project 30.5k Dec 27, 2022
An android library for displaying fps from the choreographer and percentage of time with two or more frames dropped

DEPRECATED TinyDancer is deprecated. No more development will be taking place. Check out the Google Android developer documentation for UI performance

Friendly Robot 1.9k Jan 3, 2023
Android validation library which helps developer boil down the tedious work to three easy steps.

AwesomeValidation Introduction Implement validation for Android within only 3 steps. Developers should focus on their awesome code, and let the librar

Jing Li 1.1k Dec 17, 2022
A plug and play ;) android library for displaying a "rate this app" dialog

Easy Rating Dialog This lib provides a simple way to display an alert dialog for rating app. Default conditions to show: User opened the app more than

Fernando Martínez 111 Dec 30, 2022
Tutorial For openJDK 11 and AGP 7.0.0+ | Tutorial Multi Library Android in 1 Project | Groovy

jitpack-library-guide For openJDK 11 and AGP 7.0.0 + Please read every single note for detail Tutorial Click Here Kotlin DSL Click Here Repository for

Faisal Amir 7 Dec 10, 2022