Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 816
architjn Avatar asked Jun 15 '14 10:06

architjn


People also ask

Why are my Downloads not showing in my Downloads folder?

Fix Downloads Not Showing up on Windows 10 You can click "Show in folder" to check the accurate save location. To change the default storage location, go to "Settings" > "Downloads" > "Location" > click "Change" to complete. The approach is similar to change the location of files downloaded by other browsers.

Why are my downloaded files not showing up?

You can find your files, downloaded by Chrome, by using any File Manager. In case the Downloads folder is missing, Chrome automatically saves data in the /storage/Android/data folder. You just need to find the Chrome folder in there and all previously downloaded files should be inside.


2 Answers

Try

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

This will save the file to

Environment.getExternalStorageDirectory() + "/folder"
like image 55
fatih ergin Avatar answered Oct 21 '22 23:10

fatih ergin


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");
like image 31
Nitesh Kumar Avatar answered Oct 21 '22 22:10

Nitesh Kumar