TedPermission


Source link: https://github.com/ParkSangGwon/TedPermission

What is TedPermission?

After the update to Android 6.0 Marshmallow, we have to not only declare permissions in AndroidManifest.xml, but also request them at runtime. Furthermore, user can on/off permissions in application setting anytime.
When you use dangerous permissons(ex. CAMERA, READ_CONTACTS, READ_PHONE_STATE, ...), you must check and request them runtime.
( http://developer.android.com/intl/ko/guide/topics/security/permissions.html#normal-dangerous)

You can make your own permission check logic like this, but it's so complex and hard to use functions Google offers: checkSelfPermission(), requestPermissions(), onRequestPermissionsResult(), onActivityResult().

TedPermission makes it easy to check and request android permissions.

(For Korean) ?? ???? ?? ????? ????? ??? ?????
http://gun0912.tistory.com/55

Demo



  1. Request Permissions.
  2. If user denied permissions, we will show message dialog with Setting button.

Setup

Gradle

Edit root/app/build.gradle like below.

Normal

dependencies {

  compile 'gun0912.ted:tedpermission:2.1.0' 
}

RxJava1

dependencies {

  compile 'gun0912.ted:tedpermission-rx1:2.1.0' 
}

RxJava2

dependencies {

  compile 'gun0912.ted:tedpermission-rx2:2.1.0' 
}

If you think this library is useful, please press star button at upside.



How to use

Normal

-Make PermissionListener

We will use PermissionListener for Permission Result. You will get result to onPermissionGranted(), onPermissionDenied()

 PermissionListener permissionlistener = new PermissionListener() {

@Override

public void onPermissionGranted() {

 Toast.makeText(MainActivity.this, "Permission Granted", Toast.LENGTH_SHORT).show();

}

 @Override

public void onPermissionDenied(ArrayList<String> deniedPermissions) {

 Toast.makeText(MainActivity.this, "Permission Denied\n" + deniedPermissions.toString(), Toast.LENGTH_SHORT).show();

}

 
}
;

-Start TedPermission

TedPermission class requires setPermissionListener(), setPermissions(), and check() check() will start to check permissions.

setRationaleMessage() and setDeniedMessage() are optional methods.

 TedPermission.with(this)
  .setPermissionListener(permissionlistener)
  .setDeniedMessage("If you reject permission,you can not use this service\n\nPlease turn on permissions at [Setting] > [Permission]")
  .setPermissions(Manifest.permission.READ_CONTACTS, Manifest.permission.ACCESS_FINE_LOCATION)
  .check();



RxJava1

If you use RxJava1, You can use request() method instead check() When Permission check finish, you can receive tedPermissionResult instance. tedPermissionResult instance has isGranted(), getDeniedPermissions()

 TedRxPermission.with(this)

.setDeniedMessage(

 "If you reject permission,you can not use this service\n\nPlease turn on permissions at [Setting] > [Permission]")

.setPermissions(Manifest.permission.READ_CONTACTS, Manifest.permission.ACCESS_FINE_LOCATION)

.request()

.subscribe(tedPermissionResult -> {

  if (tedPermissionResult.isGranted()) {

 Toast.makeText(RxJava1Activity.this, "Permission Granted", Toast.LENGTH_SHORT).show();

  
}
 else {

 Toast.makeText(RxJava1Activity.this,

  "Permission Denied\n" + tedPermissionResult.getDeniedPermissions().toString(), Toast.LENGTH_SHORT)

  .show();

  
}

}
, throwable -> {

}
, () -> {

}
);
 



RxJava2

Also RxJava2 can use request() like RxJava1

 TedRx2Permission.with(this)

.setRationaleTitle(R.string.rationale_title)

.setRationaleMessage(R.string.rationale_message) // "we need permission for read contact and find your location"

.setPermissions(Manifest.permission.READ_CONTACTS, Manifest.permission.ACCESS_FINE_LOCATION)

.request()

.subscribe(tedPermissionResult -> {

  if (tedPermissionResult.isGranted()) {

 Toast.makeText(this, "Permission Granted", Toast.LENGTH_SHORT).show();

  
}
 else {

 Toast.makeText(this,

  "Permission Denied\n" + tedPermissionResult.getDeniedPermissions().toString(), Toast.LENGTH_SHORT)

  .show();

  
}

}
, throwable -> {

}
, () -> {

}
);

Customize

TedPermission support this method

  • setGotoSettingButton(boolean) (default: true)
  • setRationaleTitle(R.string.xxx or String)
  • setRationaleMessage(R.string.xxx or String)
  • setRationaleConfirmText(R.string.xxx or String) (default: confirm / ??)
  • setDeniedTitle(R.string.xxx or String)
  • setDeniedMessage(R.string.xxx or String)
  • setDeniedCloseButtonText(R.string.xxx or String) (default: close / ??)
  • setGotoSettingButtonText(R.string.xxx or String) (default: setting / ??)

Also you can use util function.

  • isGranted(Context context, String... permissions): Check permissions all granted
  • isDenied(Context context, String... permissions): Check permissions all denied
  • getDeniedPermissions(Context context, String... permissions)
  • canRequestPermission(Activity activity, String... permissions): If true you can request system popup, false mean user checked Never ask again
  • startSettingActivityForResult(Activity activity)
  • startSettingActivityForResult(Activity activity, int requestCode)



Number of Cases

  1. Check permissions -> have permissions
    : onPermissionGranted() called

  2. Check permissions -> don't have permissions
    : show request dialog

  3. show request dialog -> granted permissions
    : onPermissionGranted() called

  4. show request dialog -> denied permissions
    : show denied dialog

  5. show denied dialog -> close
    : onPermissionDenied() called

  6. show denied dialog -> setting
    : startActivityForResult() to setting activity

  7. setting activity -> onActivityResult()
    : check permission

  8. check permission -> granted permissions
    : onPermissionGranted() called

  9. check permission -> denied permissions
    : onPermissionDenied() called





License

Copyright 2017 Ted Park  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

SharedPreferenceInspector provides a simple way to see shared preferences and edit them for test. No need to pull shared preferences. Just some simple clicks to see the values stored. Also with test mode to change the values and check the behavior of the app.

android-autobgbutton is a subclass of the Button widget that automatically darkens the button's background drawable when pressed, and sets it to transparent when disabled. This is inspired by iOS' automatic handling of custom background images for buttons.

AndroidPullMenu is an Open Source Android library that allows developers to easily create applications with pull menu. The aim of this library is to allow users that with a simple pull gesture to choose actions that they want to be executed.

This actions stand for refreshing options like refreshing the latest news, most viewed news, most commented views etc. or adding more actions inside view when you don’t want to implement these actions inside sliding menu. It can be implemented inside ScrollView, GridView, ListView.

Sometimes we need to show a top view above a ViewPager or ListView. DragTopLayout is a ViewGroup that contains a content view and a top menu view. You can show the top menu view just drag down the content view at the right time, or drag it up to fold.

BARACUS is the BAReknuckle Android Context USher, a tiny framework for android development enabling you to have dependency injection, dynamic context handling and database object relational mapping.

Features:

  • Dynamic context creation and destruction
  • Type based dependency injection plus documentation annotation
  • Object relational mapper
  • Dao-Approach for mapping and lazy loading / lazy references
  • Modification awareness for components - listen for data changes
  • Automatic database version and migration management
  • Hot-Backup of Sqlite
  • Declarative form validation and automatic error routing

JavaPoet is a Java API for generating .java source files.

Source file generation can useful when doing things such as annotation processing or interacting with metadata files (e.g., database schemas, protocol formats). By generating code, you eliminate the need to write boilerplate while also keeping a single source of truth for the metadata.

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