Requesting permissions

After the Android SDK version, 23 permissions are required to be requested at runtime (not for all of them). This means that we need to request them from the code as well. We will demonstrate how to do that from our application. We will request required permissions for the GPS location obtaining as a user opens the application. The user will get a dialog to approve permission if there is not any approved. Open your BaseActivity class and extend it as follows:

    abstract class BaseActivity : AppCompatActivity() {      companion object {       val REQUEST_GPS = 0       ... }      ...       override fun onCreate(savedInstanceState: Bundle?) {           super.onCreate(savedInstanceState)        ...        requestGpsPermissions() }      ... private fun requestGpsPermissions() ...

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.