Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why I can't ask for permissions in Kotlin?

I have this line, I want to ask for some permissions

ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 1)

Everything is fine, I changed the manifest, but the "permission" after the Manifest.permission is red, and showing as an error.

I’m following an Udemy course, the guy did it exactly like me, and he has no problem.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

By the way, I’m writing that code inside a function, which is outside the onCreate, but inside the MainClass, so I don’t get what I’m doing wrong

>Solution :

You need to add import android.Manifest to your list of imports, so that the compiler knows where the right Manifest comes from. My guess is that you have something else named Manifest in your import list.

So, for example, in this class from this sample project, I have that import statement. I can then use Manifest.permission, such as:

requestPerm.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE)

(FWIW, that sample is covered in this section of this free book)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading