Can't list files in directory `Download` with the ...
# android
c
Can't list files in directory
Download
with the following code:
Copy code
val directory: File = File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString())
  val files = directory.listFiles()
not kotlin but kotlin colored 4
a
Do you have required permissions?
c
yes
and i can access file created by the program
a
If your app created those files then you can access without permission
otherwise you need permission from user on run time
c
how to get that permission?
a
c
image.png
c
I have added such permission in the AndroidManifest.xml
Copy code
<!-- Devices running Android 12L (API level 32) or lower  -->
    <uses-permission
        android:name="android.permission.READ_EXTERNAL_STORAGE"
        android:maxSdkVersion="32" />
    <uses-permission
        android:name="android.permission.WRITE_EXTERNAL_STORAGE"
        android:maxSdkVersion="32"
        tools:ignore="ScopedStorage" />
    <!-- Devices running Android 13 (API level 33) or higher -->
    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
    <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
    <uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
    <uses-permission android:name="android.permission.WRITE_MEDIA_IMAGES" />
    <uses-permission android:name="android.permission.WRITE_MEDIA_VIDEO" />
    <uses-permission android:name="android.permission.WRITE_MEDIA_AUDIO" />
    <uses-permission android:name="android.permission.READ_USER_DICTIONARY" />
    <uses-permission android:name="android.permission.WRITE_USER_DICTIONARY" />
    <!-- To handle the reselection within the app on devices running Android 14
         or higher if your app targets Android 14 (API level 34) or higher.  -->
    <uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED" />
    <uses-permission android:name="android.permission.WRITE_MEDIA_VISUAL_USER_SELECTED" />
c
please continue your question in one of the resources I posted above. here we talk about the Kotlin programming language and your general android question is off topic.
hint from my side if your question is connected to https://kotlinlang.slack.com/archives/C0A974TJ9/p1729161842415829 you cannot access files on android using
File
. you should get yourself familiar with how to access files from shared storage.
c
That question is finalized. Due to the privileges problem seems not caused by ktor.