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.
You need to set this permission in your manifest.xml file
android.permission.WRITE_EXTERNAL_STORAGE
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.
If you are using Marshmallow, you have to either:
- Request permissions at runtime (the user will get to allow or deny the request) or:
- The user must go into Settings -> Apps -> {Your App} -> Permissions and grant storage access.
This is because in Marshmallow, Google completely revamped how permissions work.
If you're using a shell, the filepath to the Download (no "s") folder is
/storage/emulated/0/Download