EffortlessPermissions


Source link: https://github.com/DreaminginCodeZH/EffortlessPermissions

EffortlessPermissions

An Android permission library extending Google's EasyPermissions with convenient additions.

Don't say very easy, say effortless. —— 128 Words to Use Instead of "Very"

Sample APK

Why EffortlessPermissions?

  • Used as a drop-in replacement for Google's EasyPermissions and based on its battle-tested implementation.
  • Added an @AfterPermissionDenied annotation for methods to run automatically after denial.
  • Included consumer ProGuard rules missing in EasyPermissions which fixes your release build.
  • Added more method overloads which make coding easier.
  • Added another DialogFragment to open app detail settings which you have more control upon, e.g. dialog title can be hidden now.

In a word, just start with EffortlessPermissions instead of EasyPermissions.

Integration

Gradle:

compile 'me.zhanghai.android.effortlesspermissions:library:1.0.2'

Usage

Just use EffortlessPermission wherever you would use EasyPermissions ( documentation), and explore the improvements listed above!

And here is a fully-working sample implementation, handling permission requesting both normally and after permanent denial:

public class MainActivity extends AppCompatActivity {

private static final int REQUEST_CODE_SAVE_FILE_PERMISSION = 1;
  private static final String[] PERMISSIONS_SAVE_FILE = {

 Manifest.permission.WRITE_EXTERNAL_STORAGE
  
}
;

...

@Override
  public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,

  @NonNull int[] grantResults) {

super.onRequestPermissionsResult(requestCode, permissions, grantResults);

 // Dispatch to our library.

EffortlessPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults,

  this);

  
}

// Call back to the same method so that we'll check and proceed.
  @AfterPermissionGranted(REQUEST_CODE_SAVE_FILE_PERMISSION)
  private void saveFile() {

if (EffortlessPermissions.hasPermissions(this, PERMISSIONS_SAVE_FILE)) {

 // We've got the permission.

 saveFileWithPermission();

}
 else if (EffortlessPermissions.somePermissionPermanentlyDenied(this,

  PERMISSIONS_SAVE_FILE)) {

 // Some permission is permanently denied so we cannot request them normally.

 OpenAppDetailsDialogFragment.show(

R.string.save_file_permission_permanently_denied_message,

R.string.open_settings, this);

}
 else  {

 // Request the permissions.

 EffortlessPermissions.requestPermissions(this,

R.string.save_file_permission_request_message,

REQUEST_CODE_SAVE_FILE_PERMISSION, PERMISSIONS_SAVE_FILE);

}

  
}

@AfterPermissionDenied(REQUEST_CODE_SAVE_FILE_PERMISSION)
  private void onSaveFilePermissionDenied() {

// User denied at least some of the required permissions, report the error.

Toast.makeText(this, R.string.save_file_permission_denied, Toast.LENGTH_SHORT).show();

  
}

private void saveFileWithPermission() {

// It's show time!

Toast.makeText(this, R.string.save_file_show_time, Toast.LENGTH_SHORT).show();

  
}
 
}

Without EffortlessPermissions, you would have to make your activity implement PermissionCallbacks, check request code and call permission denied callback manually. You would also need to remember writing the ProGuard rules for every project or you'll end up debugging your release build to find it out. But now, only the truly necessary code is written. Cheers!

ProGuard

The AAR of this library has already included a consumer ProGuard file to retain the annotations and annotated methods.

License

Copyright 2017 Zhang Hai  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Resources

A library that allows you to use a CursorAdapter as the underlying data source for a RecyclerView.Adapter so that it can be used with a CursorLoader as was previously possible using the ListView.

An implementation of the "Bottom Navigation" component from Google Material Design spec.

A fast dependency injector for Android and Java. Kinject has been thought to get the following objectives:

  • Ease to configure.
  • Clean way to satisfy dependencies.
  • High performance without lose flexibility.
  • Integration little intrusive and easily abstractable.
  • Dependencies graph validation in compilation time.
  • Based on code generation.
  • Proguard friendly.

This library provides support to generate Google Material Design colored lists.

PaceholderJ is a simple Android library created to help you handle easily with screens of empty list, no items found, loading and error.

Shade Melange is a library that contains a colour palette with a wide range of pre-defined colours with their names. The implementation of the grid has been done using RecyclerView for memory efficient performance.

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