GithubHelp home page GithubHelp logo

k0shk0sh / permissionhelper Goto Github PK

View Code? Open in Web Editor NEW
1.2K 45.0 228.0 1.82 MB

Android Library to help you with your runtime Permissions.

Home Page: http://k0shk0sh.github.io/PermissionHelper/

License: Apache License 2.0

Java 100.00%

permissionhelper's Introduction

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).

permissionhelper's People

Contributors

allsimon avatar flydiverny avatar louiscad avatar maortestim avatar robderijk avatar yuyakaido avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

permissionhelper's Issues

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;

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

Group Permissions

thank you for this library but how i can make the group request permission like this group
Manifest.permission_group.STORAGE

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()?

[Feature request] Create slide without permission

The slider thing is great but it would be cooll if we can add a slide that does not ask for permission.

atm if i build a slide without calling withPermissionName it crash
java.lang.IllegalArgumentException: Unknown permission: null

Rquest without Callback

Hi,

is it possible to set a request without using the OnPermissionCallback.

Like this:


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

if user declined (boolean = false) -> ask next time again
if user really declined (boolean = false) - > open a dialog with "open Settings" buttom
if user granted (boolean = true) - > do nothing

do you know what i mean?

cheers

Requesting WRITE_SETTINGS permission

First of all thank you for this great library. However in my app I need to get WRITE_SETTINGS permission and I use following block of code.

permissions.add(PermissionModelBuilder.withContext(this)
.withCanSkip(false)
.withPermissionName(Manifest.permission.WRITE_SETTINGS)
.withTitle("CHANGE BRIGHTNESS SETTINGS")
.withMessage("This permission is required for this app to change brightness settings of this device.")
.withExplanationMessage(R.string.explanation_message_get_settings)
.withFontType("my_font.ttf")
.withLayoutColorRes(R.color.colorPrimary)
.withImageResourceId(R.drawable.permission_three)
.build());

This does not prompt me to get system settings and it simply skip to next page (using SamplePagerActivity).

I have defined uses-permission android:name="android.permission.WRITE_SETTINGS" in Manifest file as well.

Do you have any idea why? Appreciate your help. Thanks.

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.

Hello,how to use it?

i had read your demo ,but i can't find what difference with using PermissionHelper and without it.

No onPermissionNeedExplanation when requested with multiple permission

When I try to request multiple permission and user has already denied them once, it is supposed to call onPermissionNeedExplanation but it doesn't do that but this works fine it I call one permission at a time.
Please fix this issue.

Edit:
Even if I request each permission one by one it shows onPermissionNeedExplanation for only first one and for others it requests permission i.e onPermissionNeedExplanation and permission dialog gets overlapped.

When the permission(s) granted, can't know which action request the permission(s).

For Example:
In an Activity, there are two actions(download, take photos) that request Manifest.permission.WRITE_EXTERNAL_STORAGE.

Before start download action, request the permission, and then the permission is granted.
Now, What to do next? (Notice that taking photos also require and request the permission.)

The next step is to download or to take photos?

Null Pointer

Hi,

I have implemented PermissionHelper and rolled out my APK. I tested it with several phones before release, but now I get dozens of crash of my users.

Fatal Exception: java.lang.NullPointerException
Attempt to invoke virtual method 'int android.content.Context.checkPermission(java.lang.String, int, int)' on a null object reference

com.fastaccess.permission.base.PermissionFragmentHelper.isPermissionDeclined (PermissionFragmentHelper.java:348)

I use it in Fragments. Maybe context is losing it's state somehow? So we would need to check context for null?! The crash happens only on Android 8 devices. Update: Now I saw it also on Android 7.1.1

How to handle that?

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

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

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.

issue

If i disable the permission manually while running the app
(Go to the App Setting -> Disable the permission anything), our activity will have a problem.(Specifically, In a case that activity has fragments). I see that android kills the app in the circumstance.

Allow button is not working in Nexus 5

Hello,

I have checked your code is working perfectly in Nexus 6P

But i have an issue of not press Allow button Properly in Nexus 5

Please check it.

Thanks,
Dixit Patel

Close when deny or allow pressed

My app is closed when I press deny or allow, is there any solution to that?

EDIT: my bad, I've android:noHistory="true" in manifests

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);

onNoPermissionNeeded

You should provide a parameter in onNoPermissionNeeded method to distinguish multiple permissions callback;

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

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.