DownloadManager does not save downloaded files in the download folder

Whenever I try to upload any file through the code below

dm = (DownloadManager) context.getSystemService(context.DOWNLOAD_SERVICE);
request = new Request(
    Uri.parse(finalurl));
enqueue = dm.enqueue(request);

BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
                long downloadId = intent.getLongExtra(
                        DownloadManager.EXTRA_DOWNLOAD_ID, 0);
                Query query = new Query();
                query.setFilterById(enqueue);
                Cursor c = dm.query(query);
                if (c.moveToFirst()) {
                    int columnIndex = c
                            .getColumnIndex(DownloadManager.COLUMN_STATUS);
                    if (DownloadManager.STATUS_SUCCESSFUL == c
                            .getInt(columnIndex)) {

                        Toast.makeText(context, "download finished", Toast.LENGTH_LONG).show();
                    }
                }
            }
        }
    };

    context.registerReceiver(receiver, new IntentFilter(
            DownloadManager.ACTION_DOWNLOAD_COMPLETE));

The downloaded file is displayed in the Download Manager application and can be played from there at any time, but does not save the downloaded file in the Downloads folder.

If i use

.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "filename.extention"));

I get the same result.

My question is: Where do my downloads go and how can I bring them to the download folder?

+4
source share
4 answers

To view the downloaded files, the File Manager application must be installed on your phone. Steps to view downloaded files:

  • Open the File Manager application.
  • → sdcard
  • Android → data → " ", . com.xyx.abc
  • .

: storage/sdcard/Android/data/ " "

methos ""

.setDestinationInExternalFilesDir(this, dir, "abc.png");
+2

Try

request.setDestinationInExternalPublicDir("/folder","file.ext");

Environment.getExternalStorageDirectory() + "/folder"
+8

, DownloadManager ,

String file = <Cursor>.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)

: "context://downloads/my_downloads/{number}". , :

String file = <Cursor>.getColumnIndex(DownloadManager.COLUMN_LOCAL_FILENAME)

: "/data/user/0/com.android.providers.downloads/cache/{filename" "( - ), .

+1
source

Steps to find your downloads and export them to local folders. Download Manager → At the top right there is a menu button → Files → mark an item → Export.

Hope this helps :)

0
source

Source: https://habr.com/ru/post/1544640/


All Articles