Downloading a file using the Android DownloadManager to the external storage fails on Samsung Galaxy S9, S9+ on Android 9 (Pie).
Download works for Samsung Devices with Android 8 or other devices with Android 9( e.g. Pixel 2)
I have added to the manifest the following permissions:
"android.permission.WRITE_EXTERNAL_STORAGE",
"android.permission.READ_EXTERNAL_STORAGE",
"android.permission.INTERNET"
I have also requested READ/WRITE_EXTERNAL_STORAGE permissions at runtime.
The file path is: /storage/4295-DDD5/Android/data/com.example.myapplication/files/filename.file
and this filepath exists, I have created it using the Device File Explorer of AndroidStudio
The method which creates a download:
public void downloadFile(String url, String filePath) {
DownloadManager mDownloadManager =
(DownloadManager)context.getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Request request = new
DownloadManager.Request(Uri.parse(url));
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE |
DownloadManager.Request.NETWORK_WIFI);
request.setVisibleInDownloadsUi(true);
request.setDestinationUri(Uri.parse("file://" + filePath));
mDownloadManager.enqueue(request);
}
The expected result is the download of the specified file from the url to the filePath instead I am getting the following errors in logs:
D/DownloadManager: [8616] Starting com.example.myapplication
W/DownloadManager: [8616] Stop requested with status FILE_ERROR: Failed to generate filename: java.io.IOException: Permission denied
D/DownloadManager: [8616] Finished with status WAITING_TO_RETRY
V/DownloadManager: MIME Type = application/octet-stream
I/DownloadManager: Download 8616 finished with status WAITING_TO_RETRY
I/DownloadManager: Notification Clear Download 1:com.example.myapplication
from DownloadManager fails to download to external storage on Samsung with Pie
No comments:
Post a Comment