highrankin
highrankin

Reputation: 87

Kotlin - Can not access <uses-permision> in AndroidManifest file to make permission request

I'm trying to request permission to use the READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE but when I add them to the AndroidManifest file like so, I am not able to call them from my activity when I go to request permission:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

if I add the following request to my MainActivity I get an error on the names of the permissions:

ActivityCompat.requestPermissions(this,
                  arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE), RQ_PERMISSION)

However, if I have them in the manifest like this, there is no error but the permissions don't get requested.

<permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

What am I doing wrong?

Upvotes: 1

Views: 515

Answers (1)

Pavneet_Singh
Pavneet_Singh

Reputation: 37404

Make sure that you have import android.Manifest or can use

    ActivityCompat.requestPermissions(this,
        arrayOf(android.Manifest.permission.WRITE_EXTERNAL_STORAGE, android.Manifest.permission.READ_EXTERNAL_STORAGE), RQ_PERMISSION)

Upvotes: 1

Related Questions