Android

PermissionsDispatcher Library example with Google Places API (Current Location)

PermissionsDispatcher

PermissionsDispatcher Library example with Google Places API (Current Location)

As of API 23 (Marshmallow), the permission model for Android has changed significantly. Now, rather than all being setup at install-time, certain dangerous permissions must be checked and activated at runtime instead.

The easiest way to manage runtime permissions is by using third-party libraries. In this guide, we will be taking a look at PermissionsDispatcher library.

PermissionsDispatcher provides a simple annotation-based API to handle runtime permissions in Android Marshmallow, 100% reflection-free.

 

PermissionsDispatcher introduces only a few annotations, keeping its general API concise:

NOTE: Annotated methods must not be private.

Annotation Required Description
@RuntimePermissions Register an Activity or Fragment to handle permissions
@NeedsPermission Annotate a method which performs the action that requires one or more permissions
@OnShowRationale Annotate a method which explains why the permission/s is/are needed. It passes in a PermissionRequest object which can be used to continue or abort the current permission request upon user input
@OnPermissionDenied Annotate a method which is invoked if the user doesn’t grant the permissions
@OnNeverAskAgain Annotate a method which is invoked if the user chose to have the device “never ask again” about a permission

 

Current Place

Using the Google Places API for Android, you can discover the place where the device is currently located. That is, the place at the device’s currently-reported location. Examples of places include local businesses, points of interest, and geographic locations.

you must request the ACCESS_FINE_LOCATION permission.

________________________________________________________________________________________________

In this Tutorial we will learn how to implement google places api to get user current location.

How to detect GPS is on or off

We will also learn how to implement PermissionsDispatcher Library to handle runtime permission for API 23 (Marshmallow) and above (Nougat)

 

 

 

 

Reference:

Official PermissionsDispatcher Library Link

-> https://github.com/hotchemi/PermissionsDispatcher

Explanation of Runtime Permissions

-> https://guides.codepath.com/android/Managing-Runtime-Permissions-with-PermissionsDispatcher

Leave a Reply

Your email address will not be published.

10 + two =