0

I have looked at the various different versions of this question hear, and have tried some to no success.

In the code its downloading files with

 DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url.toString()));
 request.setDestinationInExternalPublicDir(dirtype, dirPath);
 long refid = mDownloadManager.enqueue(request);

with

dirType = Environment.DIRECTORY_DOWNLOADS
dirPath = MyAppCommon.MYAPP_FOLDER + "/attachments/" + attachment.getFile().toLowerCase()

Which puts them in storage/emulated/0/Download/Myapp/attachments/myfile.pdf

I need to delete the folder and all files within when my app starts up, but it will not let me delete. When I list files I only media files (which I understand is part of permission changes)

I have tried the MANAGE_EXETERAL_STORAGE permission and allowing access to all files, and that works but also requires that the app is approved to use it in the playstore, which it probably will not be.

I saw the Storage Access Framework and that seemed to prompt the user about the deletion of a file, but I want this to happen in the background as my app is the one that downloaded and stored these files.

user3074140
  • 733
  • 3
  • 13
  • 30
  • Download the content yourself (e.g., [via OkHttp](https://stackoverflow.com/a/29012988/115145)) rather than use `DownloadManager`. "as my app is the one that downloaded and stored these files" -- no, you are delegating that download operation to another system-supplied app. – CommonsWare Jan 21 '23 at 14:35
  • @CommonsWare is there a way to delete these existing ones? then redownload them with okhttp, or will they be overwritten and accessible if downloaded with okhttp – user3074140 Jan 21 '23 at 14:37
  • "is there a way to delete these existing ones?" -- perhaps using the Storage Access Framework. Otherwise, no. If you want more control, use OkHttp to download to app-specific storage, such as `getFilesDir()` or `getExternalFilesDir()` on `Context`. – CommonsWare Jan 21 '23 at 14:39

0 Answers0