PermissionHelper


Source link: https://github.com/ayz4sci/permissionHelper

PermissionHelper

A permission helper library that simplifies asking user for permission in Android M. With a customisable explanation dialog, you can easily explain to the user the permissions you need and why you need it, with buttons for permissions or take users to the app settings page in case the permission was denied.

Playstore Sample

Screenshots can be found on the store.
[PermissionHelper Sample APK] ( https://play.google.com/store/apps/details?id=com.ayz4sci.androidfactory.permissionhelpersample)

Version

1.1.0

Usage

To use this library in your android project, just simply add the following repositories and dependency into your build.gradle

dependencies {

  compile 'com.ayz4sci.androidfactory:permissionhelper:1.1.0' 
}

Also add this repository because the library is dependent on Nammu permission helper library https://github.com/tajchert/Nammu

repositories {

  maven {

url "https://jitpack.io"
  
}
 
}

In your main activity init the library as follows:

 PermissionHelper permissionHelper = PermissionHelper.getInstance(this);

Then override the following in your app root activity or the root activity where the permissions will be required:

 @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {

permissionHelper.onActivityResult(requestCode, resultCode, data);

  
}

public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {

permissionHelper.onRequestPermissionsResult(requestCode, permissions, grantResults);

  
}

@Override
  protected void onDestroy() {

permissionHelper.finish();

super.onDestroy();

  
}

Now, to perform an action that requires Android permission, call permissionHelper.verifyPermission. It accepts the following parameters:

  • String Array - description of each permission required, this will be displayed to the user in the explanation dialog.
  • String array - an array of Manifest permissions
  • PermissionCallback - you put the actions you want to perform when permission is granted or rejected. See example below:
 permissionHelper.verifyPermission(

new String[]{
"dial this number", "take picture"
}
,

new String[]{
Manifest.permission.CALL_PHONE, Manifest.permission.CAMERA
}
,

 new PermissionCallback() {

 @Override

 public void permissionGranted() {

  //action to perform when permission granteed

 
}

@Override

 public void permissionRefused() {

  //action to perform when permission refused

 
}

}

  );

To simply verify whether user has granted the permission without showing any explanation dialog or asking for permission:

  • String array - an array of Manifest permissions
  • PermissionCallback - you put the actions you want to perform when permission is granted or rejected. e.g.
 permissionHelper.verifyPermission(

new String[]{
Manifest.permission.CALL_PHONE
}
,

 new PermissionCallback() {

 @Override

 public void permissionGranted() {

  //action to perform when permission granted

 
}

@Override

 public void permissionRefused() {

  //action to perform when permission refused

 
}

}

  );

Customise Explanation UI

To modify the explanation dialog displayed to the user, use the following getters:

  • customiseUI(int background, Drawable icon) customise the background, set center (app) icon
  • getPermissionDialog() get the permission dialog
  • getCenterIcon() get the center icon (Logo), returns an ImageView
  • getNotAllowButton() get the not allow button
  • getAllowButton() get the allow button
  • getBackButton() get the back button - cancel button

That's all.

Thanks to

License

MIT

Resources

A Simple Log Tool.

An encapsulation of android.util.Log, which provides:

  • Log level control. You can display different log according different environment.
  • Log with parameters

This project aims to provide a simple and customizable pull to refresh implementation.

ContextMenu allows you can to add awesome animated context menu in your app.

Side Menu project allows to create side menu with some categories to choose.

Camera module for Android applications.

MonkeyEngine is a 3D game engine for adventurous Java developers. It’s open source, cross platform and cutting edge. And it is all beautifully documented.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes