Permission request pop up in android

Request user to give permission to read external storage in Android - (Kotlin)


if (ContextCompat.checkSelfPermission(this,
        Manifest.permission.READ_EXTERNAL_STORAGE)
    != PackageManager.PERMISSION_GRANTED) {

    // Permission is not granted    // Should we show an explanation?    if (ActivityCompat.shouldShowRequestPermissionRationale(this,
            Manifest.permission.READ_EXTERNAL_STORAGE)) {

    } else {
        // No explanation needed, we can request the permission.        ActivityCompat.requestPermissions(this,
            arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE),
            READ_STORAGE_CODE);

    }
} else {
    // Permission has already been granted}

NOTE: READ_STORAGE_CODE is just an int constant with fix value like 1001, or 2023
and is a variable in class level. 


Comments

Popular posts from this blog

GIT - SSL certificate problem: unable to get local issuer certificate

TFS -GIT CertGetCertificateChain trust error CERT_TRUST_IS_UNTRUSTED_ROOT

Convert Premium SSD to Standard HDD in Azure