Well, Android 9 (API 28) should not have this problem. However, as the Android docs specify, getExternalStoragePublicDirectory() has been deprecated in Android Q
(ndroid 10 - API 29) you can however use MediaStore with Relative Path ( Added in API level 29 ) to access Downloads
directory.
Since Relative Path
is applicable only for API level 29 and above, you may want to use it for API 29 and above and use getExternalStoragePublicDirectory()
for older APIs. (Assuming that you have used necessary Read/Write permissions)
So your code could be something similar to this -
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q){
val resolver = context.contentResolver
val contentValues = ContentValues().apply {
put(MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_DOWNLOADS)
}
val uri = resolver.insert(MediaStore.Files.getContentUri("external"), contentValues)
}else{
val dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).absolutePath
}
You can get more details about accessing media form shared storage here - Access media files from shared storage.