I am new android, i\'m making an app in which one can download files to downloads folder (using Download Manager). I can see pictures if i go to downloads folder in emulator
You need to set this permission in your manifest.xml file
android.permission.WRITE_EXTERNAL_STORAGE
If you're using a shell, the filepath to the Download (no "s") folder is
/storage/emulated/0/Download
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.
If you are using Marshmallow, you have to either:
This is because in Marshmallow, Google completely revamped how permissions work.
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 should add next permission:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
And then here is usages in code:
val externalFilesDir = context.getExternalFilesDir(DIRECTORY_DOWNLOADS)