runtime as LiveData.

For more information on LiveData refer to this link.


Add repository

repositories {
    maven {
        url  ""

Add lifecycle and permissionlivedata to your dependencies:

dependencies {

    implementation "androidx.lifecycle:lifecycle-runtime:2.0.0-rc01"
    implementation "androidx.lifecycle:lifecycle-extensions:2.0.0-rc01"
    implementation "androidx.lifecycle:lifecycle-common-java8:2.0.0-rc01"
    kapt "androidx.lifecycle:lifecycle-compiler:2.0.0-rc01"

    implementation "com.emreeran.permissionlivedata:permissionlivedata:1.0.4"


Add desired permissions to your manifest.


In Kotlin:

val permissionLiveData = PermissionLiveData.create(
        this,                                       // this being an activity or a fragment
        Manifest.permission.CAMERA,                 // Permissions to request

permissionLiveData.observe(this, Observer {
    if (it.status == Status.RECEIVED) {
        when {
            it.granted -> Timber.d("Permission ${} was granted.")
            it.shouldShowRequestPermissionRationale ->
                Timber.d("Permission ${} was denied without ask never again checked.")
            else -> Timber.d("Permission ${} was denied.")
    } else if (it.status == Status.PENDING) {
        Timber.d("Pending request for ${}")

In Java

PermissionLiveData permissionLiveData = PermissionLiveData.create(

permissionLiveData.observe(this, permission -> {
    if (permission.getStatus() == Status.RECEIVED) {
        if (permission.getGranted()) {
            Timber.d("Permission " + permission.getName() + " was granted.");
        } else if (permission.getShouldShowRequestPermissionRationale()) {
            Timber.d("Permission " + permission.getName() + " was denied without ask never again checked.");
        } else {
            Timber.d("Permission " + permission.getName() + " was denied.");
    } else if (permission.getStatus() == Status.PENDING) {
        Timber.d("Pending request for %s", permission.getName());


Copyright  Emre Eran

Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements.  See the NOTICE file distributed with this work for
additional information regarding copyright ownership.  The ASF licenses this
file to you 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, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
License for the specific language governing permissions and limitations under
the License.

Source link
thanks you RSS link


Please enter your comment!
Please enter your name here