how to access downloads folder in android?
For your first question try
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
(available since API 8)
To access individual files in this directory use either File.list() or File.listFiles(). Seems that reporting download progress is only possible in notification, see here.
Updated
getExternalStoragePublicDirectory()
is deprecated.
To get the download folder from a Fragment
,
val downloadFolder = requireContext().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
From an Activity
,
val downloadFolder = getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
downloadFolder.listFiles()
will list the File
s.
downloadFolder?.path
will give you the String path of the download folder.
Update:
The Direct filesystem access to storage has become limited in recent versions of Android.
context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
gives you the directory /emulated/0/Android/data/{package}/files/Download
. If you want to have the public downloads folder, look into the Storage Access Framework of Android documentation.