Runtime Permissions


Source link: https://github.com/karthyks/Runtime-Permissions

Runtime-Permissions

Usage

Add the following lines in the application's gradle file.


 compile 'com.android.support:appcompat-v7:25.1.1'
  compile 'com.android.support:design:25.1.1'
  compile 'com.google.android.gms:play-services-base:10.0.1'
  compile 'com.google.android.gms:play-services-location:10.0.1'
  compile 'com.github.karthyks:runtime-permissions:1.8' 

To ask the permission from the user, use the following code.

Permission permission = new Permission.PermissionBuilder(Permission.REQUEST_LOCATION)

.usingActivity(AppCompatActivity).withRationale("Some rationale message!")

.build();
 permission.requestPermission(PermissionActivity.REQUEST_PERMISSION_CODE);

or

Permission permission = new Permission.PermissionBuilder(Permission.REQUEST_LOCATION)

.usingFragment(Fragment).withRationale("Some rationale message!")

.build();
 permission.requestPermission(PermissionActivity.REQUEST_PERMISSION_CODE);

The user's response to the permission request will be reflected onActivityResult, as shown below.

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

  if (requestCode == PermissionActivity.REQUEST_PERMISSION_CODE) {

 switch (resultCode) {

case PermissionActivity.PERMISSION_GRANTED:

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

  break;

case PermissionActivity.PERMISSION_DENIED:

  Toast.makeText(this, "Denied", Toast.LENGTH_SHORT).show();

  break;

case PermissionActivity.PERMISSION_PERMANENTLY_DENIED:

  Toast.makeText(this, "Permanently denied", Toast.LENGTH_SHORT).show();

  PermissionUtil.openAppSettings(this);

  break;

default:

 
}

  
}
 else {

 super.onActivityResult(requestCode, resultCode, data);

  
}
 
}

#Simple Location Settings API implementation: To check the user's location priority which uses SettingsAPI is simplified by the following method.

LocationRequest locationRequest = new LocationRequest()

 .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

LocationSettingsHelper settingsApi = new LocationSettingsHelper(MainActivity.this,

 locationRequest, true, false);

settingsApi.checkLocationRequest();
 

And capture the result on onActivityResult.

@Override  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  if (requestCode == LocationSettingsActivity.REQUEST_LOCATION_SETTINGS) {

switch (resultCode) {

  case Activity.RESULT_OK:

 Toast.makeText(this, "Allowed Location Settings", Toast.LENGTH_SHORT).show();

 break;

  case Activity.RESULT_CANCELED:

 Toast.makeText(this, "Location Settings canceled", Toast.LENGTH_SHORT).show();

 break;

  default:

}

 
}
 else {

super.onActivityResult(requestCode, resultCode, data);

 
}
  
}
 

#Note If it throws "Permission Denied" even after allowing it, check whether all the permission is added in the manifest for the permission group. For example, for location permission add both COARSE and FINE_LOCATION permission in the manifest.

For ease of use, the permissions to be added in the manifest, for the particular dangerous permission groups are mentioned below.


 <!--

PERMISSION_GROUP PHONE
  -->
  <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
  <uses-permission android:name="android.permission.CALL_PHONE"/>
  <uses-permission android:name="android.permission.READ_CALL_LOG"/>
  <uses-permission android:name="android.permission.WRITE_CALL_LOG"/>
  <uses-permission android:name="android.permission.USE_SIP"/>
  <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>

<!--

PERMISSION_GROUP CONTACTS
  -->
  <uses-permission android:name="android.permission.GET_ACCOUNTS"/>
  <uses-permission android:name="android.permission.READ_CONTACTS"/>
  <uses-permission android:name="android.permission.WRITE_CONTACTS"/>

<!--

PERMISSION_GROUP STORAGE
  -->
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

<!--

PERMISSION_GROUP SENSORS
  -->
  <uses-permission android:name="android.permission.BODY_SENSORS"/>
  <uses-permission android:name="android.permission.USE_FINGERPRINT"/>

<!--

PERMISSION_GROUP AUDIO
  -->
  <uses-permission android:name="android.permission.RECORD_AUDIO"/>

<!--

PERMISSION_GROUP CALENDAR
  -->
  <uses-permission android:name="android.permission.READ_CALENDAR"/>
  <uses-permission android:name="android.permission.WRITE_CALENDAR"/>

<!--

PERMISSION_GROUP CAMERA
  -->
  <uses-permission android:name="android.permission.CAMERA"/>

<!--

PERMISSION_GROUP LOCATION
  -->
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<!--

PERMISSION_GROUP SMS
  -->
  <uses-permission android:name="android.permission.READ_SMS"/>
  <uses-permission android:name="android.permission.RECEIVE_SMS"/>
  <uses-permission android:name="android.permission.SEND_SMS"/>
  <uses-permission android:name="android.permission.RECEIVE_WAP_PUSH"/>
  <uses-permission android:name="android.permission.RECEIVE_MMS"/> 

Resources

Easy RecyclerView ItemDecoration. Flexible for multiple styles, such as margins, colours, drawables, show/hide, etc.

There is a bunch of useful widgets and navigation classes to make your app clear and simpler. Include features like font from asses via xml, complex background, resizable compound drawables, FlowLayout and SlideMenuLayout (expand menu from any direction), custom backstack (abstract + fragments impl).

Android EditText wrapper to support text / emoji / camera / media input.

Features

  • advance overrides to enable custom behaviour/look
  • built in media picker
    • camera capture for quick pics
    • photo/file selector
  • gif keyboard entry support
  • file/attachment preview
  • multi-file support

This Layout provide fling dismiss effect like Twitter ImageView

A custom layout that fills given width or height as per the original ratio of each child.

If given width or height is exceeded, it largely replicates the behavior of LinearLayout.

What RatioFillLayout offers:

  • Orientation: horizontal, vertical
  • Gravity: top, bottom, left, right, centerhorizontal, centervertical

What is iSortBox? Just like what it says: Simplify sorting!

This framework achieves a goal which makes sorting easier, moreover, you will benefit from what it provides such as pre-processing, converting, grouping and filtering.

As the name iSortBox, the letter 'i' means input and the letter 'o' means output, as for the details on how to complete the work, all are encapsulated in iSortBox.

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