Skip to content
/ Peko Public

Android Library for requesting Permissions with Kotlin Flow


Notifications You must be signed in to change notification settings


Repository files navigation


PErmissions with KOtlin

Quality Gate Status Android Arsenal License

Android Permissions with Kotlin Coroutines and Flow API

No more callbacks, listeners or verbose code for requesting Android permissions.
Get Permission Request Result asynchronously with one function call.
Context or Activity not needed for requests, request permissions from your View Model or Presenter.
Built with Kotlin Coroutines and Flow .

Thanks to the supporters

Supported by JetBrains Open Source

Sponsored by CloudBit


Hosted on Maven Central

implementation 'com.markodevcic:peko:3.0.5'


First initialize the PermissionRequester with Application Context. This enables all requests to be made without a Context or Activity.
If you pass an Activity as Context, IllegalStateException is raised.


Get the instance of PermissionRequester interface.

val requester = PermissionRequester.instance()

Request one or more permissions. For each permission receive PermissionResult as async Flow stream of data.

launch {
    ).collect { p ->
        when (p) {
            is PermissionResult.Granted -> print("${p.permission} granted") // nice, proceed 
            is PermissionResult.Denied -> print("${p.permission} denied") // denied, not interested in reason
            is PermissionResult.Denied.NeedsRationale -> print("${p.permission} needs rationale") // show rationale
            is PermissionResult.Denied.DeniedPermanently -> print("${p.permission} denied for good") // no go
            is PermissionResult.Cancelled -> print("request cancelled") // op canceled, repeat the request

Need to check only if permissions are granted? Let's skip the horrible Android API. No coroutine required.

val granted: Boolean = requester.areGranted(Manifest.permission.CAMERA, Manifest.permission.READ_CONTACTS)

Or are any of the requested granted?

val anyGranted: Boolean = requester.anyGranted(Manifest.permission.CAMERA, Manifest.permission.READ_CONTACTS)

Why Flows?

Requesting multiple permissions in a single request represents a data stream of PermissionsResult objects. Flow fits here perfectly. Each permission requested is either granted or denied, with Flow we can operate on each emitted result item and inspect it individually, that is check if it is Granted, Denied or Needs Rationale. Flows are async and require a coroutine to collect so this is not a huge update from Peko version 2. Also, they are now part of Kotlin Coroutines library, so no new dependencies are added.

Don't want to use Flow? No problem, suspendable extension functions that collect for you are there.

// just check all granted
launch {
    val allGranted: Boolean = requester.request(Manifest.permission.CAMERA)

// give me just granted permissions
launch {
    val granted: Collection<PermissionResult> =

// give me all denied permissions, whatever the reason
launch {
    val denied: Collection<PermissionResult> =

// these can be then separated to see needs rationale or denied permanently permissions
    val needsRationale = denied.filterIsInstance<PermissionResult.Denied.NeedsRationale>()
    val deniedPermanently = denied.filterIsInstance<PermissionResult.Denied.DeniedPermanently>()

// give me needs rationale permissions
launch {
    val needsRationale: Collection<PermissionResult> =

// give me needs denied permanently permissions
launch {
    val deniedPermanently: Collection<PermissionResult> =


Using permission requests as part of your business logic and want to run your unit tests on JVM? Perfect, PermissionRequester is an interface which can be easily mocked in your unit tests. It does not require a Context or Activity for any methods. Only a one time registration of Application Context needs to be done during app startup with PermissionRequester.initialize method.

Screen rotations

Library supports screen rotations. The only requirement is to preserve the instance of PermissionRequester during device orientation change. How to do this is entirely up to a developer. Easiest way is to use PermissionRequester with lifecycle aware Jetpack ViewModel which does this automatically.

What is new

Peko Version 3 is now released. Peko now uses coroutine Flow instead of suspend function for returning PermissionResult. Support for LiveData is removed. Flow can easily be adapted to work with LiveData.

Breaking changes from Peko Version 2

  • PermissionResult now has a single String permission as property.
  • Peko singleton is removed. PermissionRequester interface is now its replacement.
  • Extension functions for Fragment and Activity are removed.
  • PermissionLiveData class removed

Peko Version 2.0 uses vanilla Kotlin coroutines, and is here.


Copyright 2024 Marko Devcic

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

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.