architjn
architjn

Reputation: 1482

DownloadManager not storing Downloaded files in Download Folder

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?

Upvotes: 8

Views: 56249

Answers (4)

Maisterino
Maisterino

Reputation: 1

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 :)

Upvotes: 0

fatih ergin
fatih ergin

Reputation: 265

Try

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

This will save the file to

Environment.getExternalStorageDirectory() + "/folder"

Upvotes: 16

Apostolos
Apostolos

Reputation: 3445

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.

Upvotes: 2

Nitesh Kumar
Nitesh Kumar

Reputation: 5440

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");

Upvotes: 9

Related Questions