How To Get Path /storage/emulated/0/Download/file_name.mime_type For Android 10 And Above
I am saving a file inside the Downloads directory of the device (Android 11) to be viewed later by my app. I'm allowing multiple file types like pdf, word etc. I was able to save t
Solution 1:
Try with the following code it will help you.
private fun readFile(){
val FILENAME = "user_details.txt"
val dir = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
File(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
.toString() + "/" + "folderName"
)
} else {
File(
Environment.getExternalStorageDirectory()
.toString() + "/${Environment.DIRECTORY_DOWNLOADS}/" + "folderName"
)
}
dir.apply {
if(this.exists()) File(this, FILENAME).apply {
FileInputStream(this).apply {
val stringBuffer = StringBuffer()
var i: Int
while (this.read().also { i = it } != -1) {
stringBuffer.append(i.toChar())
}
close()
}
}
}
}
Solution 2:
You can use
{Environment.DIRECTORY_DOWNLOADS} + "/folderName/file_name.mime_type"
Solution 3:
/storage/emulated/0/Download/12d82c65-00a5-4c0a-85bc-238c28005c33.bin
Post a Comment for "How To Get Path /storage/emulated/0/Download/file_name.mime_type For Android 10 And Above"