Permissify


Source link: https://github.com/holidaycheck/Permissify

Permissify - Simplifying Android Permissions

Permissify is an Android library that makes requesting permissions at runtime much easier.

Android Marshmallow added a new functionality to let users grant permissions when running an app instead of granting them all when installing it. This approach gives the user more control but requires developers to add lots of boilerplate code to support it.

Overview

  • Tested in production - over 1000 000 installs in the Holidaycheck app
  • Handles showing Rationale & Permission denied dialogs
  • Consistent API across android versions
  • Perfectly fine with configuration changes
  • API for activity and fragment
  • Works great without hacking android
  • No memory leaks guaranteed
  • Supports Android 15+

Screenshots

Add it to your project

Include the library in your build.gradle

dependencies{

  compile 'com.holidaycheck:permissify:1.0.0' 
}

or to your pom.xml if you are using Maven

<dependency>
  <groupId>com.holidaycheck</groupId>
  <artifactId>permissify</artifactId>
  <version>1.0.0</version>
  <type>aar</type> </dependency> 

Configuration

To start using the library you need to extend your activity from PermissifyActivity and configure library in your custom android.app.Application.

Minimum configuration to run is presented below. You basically need to provide translations for every Permission group that is used in your app.

public class Application extends android.app.Application {

@Override
  public void onCreate() {

super.onCreate();

 PermissifyConfig permissifyConfig = new PermissifyConfig.Builder()

 .withDefaultTextForPermissions(new HashMap<String, DialogText>() {
{

put(Manifest.permission_group.LOCATION, new DialogText(R.string.location_rationale, R.string.location_deny_dialog));

put(Manifest.permission_group.CAMERA, new DialogText(R.string.camera_rationale, R.string.camera_deny_dialog));

  
}

}
)

.build();

 PermissifyConfig.initDefault(permissifyConfig);

  
}
 
}

Full configuration looks like this, but mostly you will use minimum config. You can customize default options for every permission call, and dialogs appearance. See javadoc for more details.

PermissifyConfig permissifyConfig = new PermissifyConfig.Builder()
  .withDefaultPermissionCallOptions(

new PermissionCallOptions.Builder()

 .withDefaultDenyDialog(true)

 .withDefaultRationaleDialog(true)

 .withDefaultRationaleDialog(R.string.default_rationale_dialog_text)

 .withDenyDialogMsg(R.string.default_deny_dialog_text)

 .withRationaleEnabled(true)

 .build()
  )
  .withDefaultTextForPermissions(new HashMap<String, DialogText>() {
{

put(Manifest.permission_group.LOCATION, new DialogText(R.string.location_rationale, R.string.location_deny_dialog));

put(Manifest.permission_group.CAMERA, new DialogText(R.string.camera_rationale, R.string.camera_deny_dialog));

  
}

}
)
  .withPermissionTextFallback(new DialogText(R.string.fallback_rationale_dialog_text, R.string.fallback_deny_dialog_text))
  .withDialogRationaleDialogFactory(new PermissifyConfig.AlertDialogFactory() {

@Override

public AlertDialog createDialog(Context context, String dialogMsg, DialogInterface.OnClickListener onClickListener) {

 return new CustomRationaleDialog(context, dialogMsg, onClickListener);

}

  
}
)
  .withDenyDialogFactory(new PermissifyConfig.AlertDialogFactory() {

@Override

public AlertDialog createDialog(Context context, String dialogMsg, DialogInterface.OnClickListener onClickListener) {

 return new CustomDenyDialog(context, dialogMsg, onClickListener);

}

  
}
)
  .build();
  PermissifyConfig.initDefault(permissifyConfig);

Usage

To request specific permission you need make a call to PermissifyManager. Every call is associated with your unique RequestId.

getPermissifyManager().callWithPermission(this, LOCATION_PERMISSION_REQUEST_ID, android.Manifest.permission.ACCESS_FINE_LOCATION);

the result and the current permission status is provided via

@Override public void onCallWithPermissionResult(int callId, PermissifyManager.CallRequestStatus status) {

  if (callId == LOCATION_PERMISSION_REQUEST_ID) {

switch (status) {

 case PERMISSION_GRANTED:

  getUserLocation();

 break

 case PERMISSION_DENIED_ONCE:

 //do some custom logic

 break;

 case PERMISSION_DENIED_FOREVER:

 //do some custom logic

 case SHOW_PERMISSION_RATIONALE:

 //do some custom logic

}

  
}
 
}

If you want to request permission from a fragment make sure it implements PermissifyManager.Callback

There are two types of dialogs:

  • Rationale dialog - is shown in situations where the user might need an explanation why the app needs this permission
  • Deny dialog - is shown when the user permanently denied requested permission

There are number of options that you can change when requesting for permission using additional parameter:

getPermissifyManager().callWithPermission(this, LOCATION_PERMISSION_REQUEST_ID, android.Manifest.permission.ACCESS_FINE_LOCATION,

 new PermissionCallOptions.Builder()

  .withDefaultDenyDialog(false)

  .withRationaleEnabled(false)

  .build());

Current limitations

  • Multiple permission request at once is not currently supported (will be added soon)

Do you want to contribute?

Feel free to add any cool and useful feature to the library.

License

The MIT License (MIT)  Copyright (c) 2016 HolidayCheck  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 

Resources

Android - MaterialPreference

  • A simple backward-compatible implementation of a Material Design Preference aka settings item
  • XML layouts are taken from Android Platform Framework Base

An eventbus library for android, simplifies communication between Activities, Fragments, Threads, Services, etc.

A simple implementation of pull-to-refresh ListView.

Generates Retrofit interfaces and related models from Google Cloud Endpoint (GCE) discovery files.

Ready-to-use view pagers for your project.

YouTubeHelper allows to fetch information from YouTube. You can get info about videos, users, comments, etc.

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