Doing it the Kotlin way

What happens if our application requires a lot of permissions that must be handled through the code? It happens that we have a lot of code handling different permission requests. This means that we have a lot of boilerplate code! Luckily for us, we are using Kotlin. Kotlin will be our tool to make things simpler!

Create a new package called permission. Then create two new Kotlin files as follows:

PermissionCompatActivity and PermissionRequestCallback.

Let's define the permission request callback as follows:

     package com.journaler.permission 
 
     interface PermissionRequestCallback { 
       fun onPermissionGranted(permissions: List<String>) 
       fun onPermissionDenied(permissions: List<String>) 
     } 

This will be the callback that will ...

Get Mastering Android Development with Kotlin now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.