• Stars
    star
    1,227
  • Rank 38,235 (Top 0.8 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created about 9 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Android Library to help you with your runtime Permissions.

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

More Repositories

1

FastHub

FastHub the ultimate GitHub client for Android.
Java
5,706
star
2

FastAccess

A tiny launcher or as Samsung likes to call it Floating Toolbox.
Java
309
star
3

RetainedDateTimePickers

Android Library to help you with your date & time pickers while retaining the instance of the pickers on orientation change.
Java
106
star
4

KAM

KAM is an apk manager, backup, restore and more.
Java
84
star
5

Android-MVP-for-dummies

this is simple application demonstrate how structuring MVP project in Android.
Java
49
star
6

ComposeEasyForms

Compose easy forms validation library
Kotlin
26
star
7

AndroidFloatingImage

this example explains how to code a floating imageView on top of your apps and with the ability to move it around the screen.
Java
15
star
8

EasyVersion

EasyVersion is a Gradle plugin that manage your app or library version.
Kotlin
9
star
9

android-api-SecureKeys

Store sensible data in a simple and secure way
C++
8
star
10

Filtra-StyleMe-

Filtra is replacement for my old project (Style Me Photo Editor) as i don't maintain that project any more, i decided to create it from scratch for more enhancements and features.
Java
7
star
11

FastHub-code-theme-images

6
star
12

cloen

`git clone` wrapper. Clones a repository, cds into it, and opens it in $EDITOR|$GUI_EDITOR.
Shell
4
star
13

NewKam

This is new implementation of KAM (App Manager) that i thought of revamping the whole base code & UI. i chose to do this as i don't have much time to rebase the old repo.
Java
4
star
14

assignmentReminder

Assignment reminder built using Phonegap.
CSS
3
star
15

Cheaphlight

Cheaphlight, is an un-official client for Google Flight. a work in progress.
Java
3
star
16

ComposeGists

Testing Android Comopse
Kotlin
3
star
17

AwesomeToaster

AwesomeToaster breaks the limitation of the android default Toast Message. AwesomeToaster is designed following the Material Design and it works from API 8 until today's API
Java
2
star
18

The-Flash

The Flash Launcher ( a work in progress ) yet another launcher but not like others.
Java
1
star
19

k0shk0sh.github.io

1
star
20

TouchWiz4Launcher

TouchWiz4 for Android Phones-tablets install along side the stock launcher
1
star
21

android-active-record

Automatically exported from code.google.com/p/android-active-record
HTML
1
star