DownloadManager not storing Downloaded files in Download Folder
Asked Answered
I

4

8

Whenever i try to download 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 file downloaded shows in Download Manager Application and can be played from there any time but that is not storing the downloaded file in Downloads folder.

If i use

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

i get the same result.

My question is- Where are my downloads going and how can i bring them to downloads folder?

Itu answered 15/6, 2014 at 10:56 Comment(0)
S
9

To see the downloaded files, you must have File Manager app installed in your phone. Steps to view downloaded files:

  1. Open File Manager app.
  2. Go to storage -> sdcard
  3. Go to Android -> data -> "Your package name" eg. com.xyx.abc
  4. Here are all your downloads.

Path is: storage/sdcard/Android/data/"your package"

Use below methos to save files in Download folder

.setDestinationInExternalFilesDir(this, dir, "abc.png");
Sanguinaria answered 1/8, 2014 at 9:39 Comment(0)
T
16

Try

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

This will save the file to

Environment.getExternalStorageDirectory() + "/folder"
Trinitroglycerin answered 16/8, 2016 at 20:13 Comment(0)
S
9

To see the downloaded files, you must have File Manager app installed in your phone. Steps to view downloaded files:

  1. Open File Manager app.
  2. Go to storage -> sdcard
  3. Go to Android -> data -> "Your package name" eg. com.xyx.abc
  4. Here are all your downloads.

Path is: storage/sdcard/Android/data/"your package"

Use below methos to save files in Download folder

.setDestinationInExternalFilesDir(this, dir, "abc.png");
Sanguinaria answered 1/8, 2014 at 9:39 Comment(0)
R
2

If you try to find where the DownloadManager stored the file using

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

you get a ficticious path: "context://downloads/my_downloads/{number}". To see the actual path, use:

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

You then get: "/data/user/0/com.android.providers.downloads/cache/{filename}" (or something similar) and you can access the file from there.

Rightminded answered 10/4, 2016 at 20:4 Comment(0)
M
0

Steps to find your downloads and export them to local folders. Download Manager - > Top right there is a menu button - > files - > mark the item(s) - > export.

Hope it helped :)

Melentha answered 20/1, 2019 at 4:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.